forked from Tagics/tagics.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
27 lines (21 loc) · 894 Bytes
/
index.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
const { createServer } = require("node:http");
const { createBareServer } = require("@tomphttp/bare-server-node");
const { uvPath } = require("@titaniumnetwork-dev/ultraviolet");
const express = require("express");
const port = 8000;
const app = express();
app.use(express.static("public", { extensions: ['html', 'htm'] }));
app.get('/load/:id', (req, res) => { res.sendFile(__dirname + '/public/load.html') })
const server = createServer();
const bare = createBareServer("/bare/");
app.use("/uv/", express.static(uvPath));
app.use((req, res) => { res.status(404).end('error page not found.'); });
server.on("request", (req, res) => {
if (bare.shouldRoute(req)) bare.routeRequest(req, res);
else app(req, res);
});
server.on("upgrade", (req, socket, head) => {
if (bare.shouldRoute(req)) bare.routeUpgrade(req, socket, head);
else socket.end();
});
server.listen({ port: port, });