Replace serve-static with express for simplicity. #6
This commit is contained in:
parent
e3bdd299e4
commit
7ffc02dc60
3 changed files with 691 additions and 45 deletions
699
package-lock.json
generated
699
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -18,7 +18,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@titaniumnetwork-dev/ultraviolet": "^1.0.2",
|
"@titaniumnetwork-dev/ultraviolet": "^1.0.2",
|
||||||
"@tomphttp/bare-server-node": "^1.0.4-deps1",
|
"@tomphttp/bare-server-node": "^1.0.4-deps1",
|
||||||
"serve-static": "^1.15.0",
|
"express": "^4.18.2",
|
||||||
"ultraviolet-static": "github:titaniumnetwork-development/Ultraviolet-Static"
|
"ultraviolet-static": "github:titaniumnetwork-development/Ultraviolet-Static"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
35
src/index.js
35
src/index.js
|
|
@ -1,36 +1,21 @@
|
||||||
import createBareServer from "@tomphttp/bare-server-node";
|
import createBareServer from "@tomphttp/bare-server-node";
|
||||||
|
import express from "express";
|
||||||
import { createServer } from "node:http";
|
import { createServer } from "node:http";
|
||||||
import serveStatic from "serve-static";
|
|
||||||
import { publicPath } from "ultraviolet-static";
|
import { publicPath } from "ultraviolet-static";
|
||||||
import uvPath from "@titaniumnetwork-dev/ultraviolet";
|
import uvPath from "@titaniumnetwork-dev/ultraviolet";
|
||||||
|
|
||||||
const bare = createBareServer("/bare/");
|
const bare = createBareServer("/bare/");
|
||||||
const serve = serveStatic(publicPath, { fallthrough: false });
|
const app = express();
|
||||||
const serveUV = serveStatic(uvPath, { fallthrough: false });
|
|
||||||
|
// Load our publicPath first and prioritize it over UV.
|
||||||
|
app.use(express.static(publicPath));
|
||||||
|
// Load vendor files last.
|
||||||
|
// The vendor's uv.config.js won't conflict with our uv.config.js inside the publicPath directory.
|
||||||
|
app.use("/uv/", express.static(uvPath));
|
||||||
|
|
||||||
const server = createServer();
|
const server = createServer();
|
||||||
|
|
||||||
server.on("request", (req, res) => {
|
server.on("request", (req, res) => app(req, res));
|
||||||
if (bare.shouldRoute(req)) {
|
|
||||||
bare.routeRequest(req, res);
|
|
||||||
} else {
|
|
||||||
if (req.url.startsWith("/uv/")) {
|
|
||||||
req.url = req.url.slice("/uv".length);
|
|
||||||
serveUV(req, res, (err) => {
|
|
||||||
res.writeHead(err?.statusCode || 500, null, {
|
|
||||||
"Content-Type": "text/plain",
|
|
||||||
});
|
|
||||||
res.end(err?.stack);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
serve(req, res, (err) => {
|
|
||||||
res.writeHead(err?.statusCode || 500, null, {
|
|
||||||
"Content-Type": "text/plain",
|
|
||||||
});
|
|
||||||
res.end(err?.stack);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
server.on("upgrade", (req, socket, head) => {
|
server.on("upgrade", (req, socket, head) => {
|
||||||
if (bare.shouldRoute(req, socket, head)) {
|
if (bare.shouldRoute(req, socket, head)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue