-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
26 lines (21 loc) · 925 Bytes
/
server.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
var http = require('http');
var url = require('url');
var statix = require('node-static');
var queries = require('./queries');
// Will serve files from "public" directory
// Files from this server are not cached (to make debugging easier)
var staticFileServer = new statix.Server('./public',{cache: 0});
function handler (request,response) {
console.log("got request for "+request.url);
var urlStr = request.url;
var urlObj = url.parse(urlStr); // an object
var pathname = urlObj.pathname; // the pathname part of the url
var search = urlObj.search; // the query part
if ((search != undefined) && (pathname == "/query")) {
queries.queryServer(request,response,search);
} else {
staticFileServer.serve(request,response);
}
}
server = http.createServer(handler);
server.listen(process.env.PORT || 5000); // use your port number here!