Nebula/app.mjs
2022-06-07 18:48:04 -04:00

43 lines
No EOL
1.2 KiB
JavaScript

import Server from 'bare-server-node';
import http from 'http';
import nodeStatic from 'node-static';
import fs from 'fs';
const custombare = require('./static/customBare.js');
const bare = new Server('/bare/', '');
const serve = new nodeStatic.Server('static/');
const patronServe = new nodeStatic.Server('static/');
const fakeServe = new nodeStatic.Server('fakeStatic/');
const server = https.createServer();
fs.readdir('/etc/letsencrypt/live', { withFileTypes: true }, (err, files) => {
if (!err)
files
.filter(file => file.isDirectory())
.map(folder => folder.name)
.forEach(dir => {
server.addContext(dir, {
key: fs.readFileSync(`/etc/letsencrypt/live/${dir}/privkey.pem`),
cert: fs.readFileSync(`/etc/letsencrypt/live/${dir}/fullchain.pem`)
});
});
});
server.on('request', (request, response) => {
if (custombare.isBare(request, response)) {
custombare.route(request,response);
}
if (bare.route_request(request, response)) return true;
serve.serve(request, response);
});
server.on('upgrade', (req, socket, head) => {
if (bare.route_upgrade(req, socket, head))
return;
socket.end();
});
server.listen(443);