-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpServer.js
34 lines (29 loc) · 971 Bytes
/
httpServer.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
34
const handler = require("serve-handler");
const http = require("http");
const fs = require("fs");
const requestListener = (request, response) => {
// You pass two more arguments for config and middleware
// More details here: https://github.com/vercel/serve-handler#options
response.setHeader("Access-Control-Allow-Origin", "*");
// response.setHeader(
// "Access-Control-Allow-Methods",
// "GET, POST, OPTIONS, PUT, PATCH, DELETE"
// );
response.setHeader("Access-Control-Allow-Methods", "GET");
response.setHeader(
"Access-Control-Allow-Headers",
"X-Requested-With,content-type"
);
response.setHeader("Access-Control-Allow-Credentials", true);
return handler(request, response, {
public: "./downloads",
});
};
const server = http.createServer(requestListener);
var port = process.argv.slice(2)[0];
if (!port) {
port = 3031;
}
server.listen(port, () => {
console.log("Running at http://localhost:" + port);
});