-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodeServer.js
33 lines (23 loc) · 898 Bytes
/
nodeServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const http = require('http');
const url = require('url');
const myFetch = require('./Scripts/nodeGetJSON.js');
const server = http.createServer((req, res) => {
const qObj = url.parse(req.url, true, true);
console.log(qObj.host);
console.log(qObj.pathname);
console.log(qObj.search);
if (qObj.pathname = "/api") {
console.log("Api Hit");
// RegExp to find exactly 9 chars in the search string
var testStr = RegExp(/^[0-9]{9}$/);
// test if the search string matches the ally code format of 9 digits
if (testStr.test(qObj.query.player)) {
// perform the get and place the data in the AcctData folder
console.log("passed");
console.log(qObj.query);
myFetch.getJSON(qObj.query.player);
}
}
});
server.listen(3000);
console.log("listening on port 3000")