forked from UseInterstellar/Interstellar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
3 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,3 @@ | ||
import createBareServer from "@tomphttp/bare-server-node"; | ||
import express from "express"; | ||
import { createServer } from "node:http"; | ||
import { publicPath } from "ultraviolet-static"; | ||
import { uvPath } from "@titaniumnetwork-dev/ultraviolet"; | ||
import { join } from "node:path"; | ||
import { hostname } from "node:os"; | ||
|
||
const bare = createBareServer("/bare/"); | ||
const app = express(); | ||
|
||
// 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)); | ||
|
||
// Error for everything else | ||
app.use((req, res) => { | ||
res.status(404); | ||
res.sendFile(join(publicPath, "404.html")); | ||
}); | ||
|
||
const server = createServer(); | ||
|
||
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(); | ||
} | ||
}); | ||
|
||
let port = parseInt(process.env.PORT || ""); | ||
|
||
if (isNaN(port)) port = 8080; | ||
|
||
server.on("listening", () => { | ||
const address = server.address(); | ||
|
||
// by default we are listening on 0.0.0.0 (every interface) | ||
// we just need to list a few | ||
console.log("Listening on:"); | ||
console.log(`\thttp://localhost:${address.port}`); | ||
console.log(`\thttp://${hostname()}:${address.port}`); | ||
console.log( | ||
`\thttp://${ | ||
address.family === "IPv6" ? `[${address.address}]` : address.address | ||
}:${address.port}` | ||
); | ||
}); | ||
|
||
server.listen({ | ||
port, | ||
}); | ||
(async() => { | ||
await import('./index.mjs'); | ||
})(); |