-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpsServer.js
32 lines (28 loc) · 915 Bytes
/
httpsServer.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
const handler = require("serve-handler");
const https = require("https");
const fs = require("fs");
const options = {
key: fs.readFileSync("ssl/key.pem"),
cert: fs.readFileSync("ssl/cert.pem"),
};
const server = https.createServer(options, (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");
response.setHeader(
"Access-Control-Allow-Headers",
"X-Requested-With,content-type"
);
response.setHeader("Access-Control-Allow-Credentials", true);
return handler(request, response, {
public: "./downloads",
});
});
var port = process.argv.slice(2)[0];
if (!port) {
port = 3031;
}
server.listen(port, () => {
console.log("Running at https://localhost:" + port);
});