-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (22 loc) · 784 Bytes
/
server.js
File metadata and controls
27 lines (22 loc) · 784 Bytes
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
var http = require('http');
var fs = require('fs');
var server = http.createServer(function(req, res) {
if (req.method === "GET") {
res.writeHead(200, { "Content-Type" : "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept" });
var readable = fs.createReadStream(`./src/${req.url}`);
readable.pipe(res);
} else if (req.method === "POST") {
var body = "";
req.on("data", function (chunk) {
body += chunk;
});
req.on("end", function(){
res.writeHead(200, { "Content-Type": "text/html" });
res.end(body);
});
}
console.log(req.url);
});
server.listen(5000);