Prepare
This commit is contained in:
parent
73e3271bef
commit
5719fc8930
2 changed files with 21 additions and 63 deletions
80
app.mjs
80
app.mjs
|
|
@ -1,73 +1,35 @@
|
||||||
import createBareServer from '@tomphttp/bare-server-node';
|
import createBareServer from '@tomphttp/bare-server-node';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import https from 'https';
|
|
||||||
import nodeStatic from 'node-static';
|
import nodeStatic from 'node-static';
|
||||||
import fs from 'fs';
|
|
||||||
import * as custombare from './static/customBare.mjs';
|
import * as custombare from './static/customBare.mjs';
|
||||||
|
|
||||||
|
const PORT = process.env.PORT || 3000;
|
||||||
const httpPort = 80;
|
|
||||||
const httpsPort = 443;
|
|
||||||
const debug = true;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const bareServer = createBareServer('/bare/', {
|
const bareServer = createBareServer('/bare/', {
|
||||||
logErrors: false,
|
logErrors: false,
|
||||||
localAddress: undefined,
|
localAddress: undefined
|
||||||
maintainer: {
|
|
||||||
email: 'tomphttp@sys32.dev',
|
|
||||||
website: 'https://github.com/tomphttp/',
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const serve = new nodeStatic.Server('static/');
|
const serve = new nodeStatic.Server('static/');
|
||||||
const patronServe = new nodeStatic.Server('static/');
|
|
||||||
const fakeServe = new nodeStatic.Server('fakeStatic/');
|
|
||||||
|
|
||||||
const httpServer = http.createServer();
|
const server = http.createServer();
|
||||||
const httpsServer = https.createServer();
|
|
||||||
|
|
||||||
fs.readdir('/etc/letsencrypt/live', { withFileTypes: true }, (err, files) => {
|
server.on('request', (request, response) => {
|
||||||
if (!err)
|
if (custombare.route(request, response)) return true;
|
||||||
files
|
|
||||||
.filter(file => file.isDirectory())
|
if (bareServer.shouldRoute(request)) {
|
||||||
.map(folder => folder.name)
|
bareServer.routeRequest(request, response);
|
||||||
.forEach(dir => {
|
} else {
|
||||||
httpsServer.addContext(dir, {
|
serve.serve(request, response);
|
||||||
key: fs.readFileSync(`/etc/letsencrypt/live/${dir}/privkey.pem`),
|
}
|
||||||
cert: fs.readFileSync(`/etc/letsencrypt/live/${dir}/fullchain.pem`)
|
});
|
||||||
});
|
server.on('upgrade', (req, socket, head) => {
|
||||||
});
|
if (bareServer.shouldRoute(req)) {
|
||||||
|
bareServer.routeUpgrade(req, socket, head);
|
||||||
|
} else {
|
||||||
|
socket.end();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
httpServer.on('request', request);
|
server.listen(PORT);
|
||||||
httpsServer.on('request', request);
|
|
||||||
httpServer.on('upgrade', upgrade);
|
|
||||||
httpsServer.on('upgrade', upgrade);
|
|
||||||
|
|
||||||
function request(request, response) {
|
console.log(`Server running at http://localhost:${PORT}/.`);
|
||||||
if (custombare.route(request, response)) return true;
|
|
||||||
if (debug === true) {
|
|
||||||
console.log(`[${request.method}] - ${request.url} - LINK: ${request.headers['host']} - AGENT: ${request.headers['user-agent']}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bareServer.shouldRoute(request)) {
|
|
||||||
bareServer.routeRequest(request, response);
|
|
||||||
} else {
|
|
||||||
serve.serve(request, response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function upgrade(req, socket, head) {
|
|
||||||
if (bareServer.shouldRoute(req)) {
|
|
||||||
bareServer.routeUpgrade(req, socket, head);
|
|
||||||
} else {
|
|
||||||
socket.end();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
httpServer.listen(httpPort);
|
|
||||||
httpsServer.listen(httpsPort);
|
|
||||||
|
|
||||||
console.log("Server running on http://localhost:" + httpPort + " and https://localhost:" + httpsPort);
|
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,6 @@
|
||||||
<meta property="og:type" content="website">
|
<meta property="og:type" content="website">
|
||||||
<meta property="og:image" content="/images/logo.png">
|
<meta property="og:image" content="/images/logo.png">
|
||||||
<meta property="og:description" content="Nebula Web">
|
<meta property="og:description" content="Nebula Web">
|
||||||
<script>
|
|
||||||
if (location.protocol === "http:" && location.host !== "localhost") location.protocol = "https:";
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue