Skip to content

Commit

Permalink
Updated Ultraviolet & Bare Server
Browse files Browse the repository at this point in the history
  • Loading branch information
xbubbo authored Jun 15, 2023
1 parent 009de6a commit 5207bd7
Show file tree
Hide file tree
Showing 11 changed files with 2,035 additions and 41,298 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node_modules/
node_modules
56 changes: 5 additions & 51 deletions .replit
Original file line number Diff line number Diff line change
@@ -1,59 +1,13 @@
language = "nodejs"
run = "npm run start"
language = "nix"
run = ["npm", "start"]

[env]
XDG_CONFIG_HOME = "/home/runner/.config"
PATH = "/home/runner/$REPL_SLUG/.config/npm/node_global/bin:/home/runner/$REPL_SLUG/node_modules/.bin"
npm_config_prefix = "/home/runner/$REPL_SLUG/.config/npm/node_global"
[packager]
language = "nodejs-npm"

[nix]
channel = "stable-22_05"

[packager]
language = "nodejs"

[packager.features]
packageSearch = true
guessImports = true
enabledForHosting = false

[debugger]
support = true

[debugger.interactive]
transport = "localhost:0"
startCommand = ["dap-node"]

[debugger.interactive.initializeMessage]
command = "initialize"
type = "request"

[debugger.interactive.initializeMessage.arguments]
clientID = "replit"
clientName = "replit.com"
columnsStartAt1 = true
linesStartAt1 = true
locale = "en-us"
pathFormat = "path"
supportsInvalidatedEvent = true
supportsProgressReporting = true
supportsRunInTerminalRequest = true
supportsVariablePaging = true
supportsVariableType = true

[debugger.interactive.launchMessage]
command = "launch"
type = "request"

[debugger.interactive.launchMessage.arguments]
console = "externalTerminal"
cwd = "."
pauseForSourceMap = false
program = "./index.js"
request = "launch"
sourceMaps = true
stopOnEntry = false
type = "pwa-node"

[unitTest]
language = "nodejs"
language = "nodejs"
52 changes: 36 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { createBareServer } from "@tomphttp/bare-server-node";
import express from "express";
import http from "node:http";
import createBareServer from "@tomphttp/bare-server-node";
import path from "node:path";
import { createServer } from "node:http";
import { join } from "node:path";
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);

const __dirname = path.dirname(__filename);

import * as dotenv from "dotenv";
dotenv.config();

const __dirname = process.cwd();
const server = http.createServer();
const app = express(server);
const bareServer = createBareServer("/bare/");
const bare = createBareServer("/bare/");
const app = express();

app.use(express.json());
app.use(
Expand Down Expand Up @@ -59,27 +64,42 @@ app.get("/*", (req, res) => {
res.redirect("/404");
});

// Bare Server
const server = createServer();

server.on("request", (req, res) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeRequest(req, res);
if (bare.shouldRoute(req)) {
bare.routeRequest(req, res);
} else {
app(req, res);
}
});

server.on("upgrade", (req, socket, head) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeUpgrade(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", () => {
console.log(`Interstellar running at http://localhost:${process.env.PORT}`);
});
console.log(`Interstellar running at http://localhost:${process.env.PORT}`);
});

process.on("SIGINT", shutdown);
process.on("SIGTERM", shutdown);

function shutdown() {
console.log("SIGTERM signal received: closing HTTP server");
server.close();
bare.close();
process.exit(0);
}

server.listen({
port: process.env.PORT,
});
port: process.env.PORT,
});
Loading

0 comments on commit 5207bd7

Please sign in to comment.