Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
FEAT: WISP SUPPORT and a couple other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
IncognitoTGT committed Apr 2, 2024
1 parent 69579ee commit c565ff4
Show file tree
Hide file tree
Showing 23 changed files with 245 additions and 291 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<script src="/uv/uv.bundle.js" defer></script>
<script src="/uv/uv.config.js" defer></script>
<script src="/epoxy/index.js" defer></script>

<script src="/libcurl/index.js" defer></script>
</head>
<body>
<div id="root"></div>
Expand Down
40 changes: 4 additions & 36 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env tsx
import { createServer, IncomingMessage } from "node:http";
import { createServer } from "node:http";
import { createServer as createViteServer } from "vite";
import { createBareServer } from "@tomphttp/bare-server-node";
import express from "express";
import path from "path";
import cors from "cors";
Expand All @@ -11,7 +10,6 @@ import { Socket } from "node:net";
import wisp from "wisp-server-node";
const devMode = argv.includes("--dev");
const usingMasqr = process.env.MASQR || argv.includes("--masqr");
const noIpLeak = argv.includes("--no-ip-leak");
const port =
process.env.PORT ||
(argv.includes("--port") && argv[argv.indexOf("--port") + 1]) ||
Expand All @@ -26,18 +24,9 @@ default: Run in production mode
--dev: Run in development mode
--help, -h: Display this help message
--masqr: Enable masqr
--no-ip-leak: only allow going to asdf.com
`);
process.exit(0);
}
const bare = createBareServer("/bend/", {
blockLocal: false,
maintainer: {
website: "https://z1g-project.vercel.app",
// todo: change this
email: process.env.MAINTAINER_EMAIL || "[email protected]",
},
});
const vite = await createViteServer({
server: { middlewareMode: true },
});
Expand Down Expand Up @@ -68,36 +57,15 @@ if (!devMode) {
}

const server = createServer();
server.on("request", (request, response) => {
if (bare.shouldRoute(request)) {
if (noIpLeak) {
if (
request.headers["x-bare-host"] &&
request.headers["x-bare-host"] != "asdf.com"
) {
console.log(request.headers);
request.socket.write(
'HTTP/1.1 406 Not Acceptable\n\n"NO LEAKING MY IP!!! GO TO ASDF.COM NOW"',
);
request.socket.end();
}
}
bare.routeRequest(request, response);
} else {
app(request, response);
}
});
server.on("request", app);

server.on("upgrade", (req: IncomingMessage, socket: Socket, head) => {
if (bare.shouldRoute(req)) {
bare.routeUpgrade(req, socket, head);
} else if (req.url.endsWith("/wisp/")) {
server.on("upgrade", (req, socket: Socket, head) => {
if (req.url.endsWith("/wisp/")) {
wisp.routeRequest(req, socket, head);
}
});
server.listen(port);
console.log(`
\x1b[34;49;1m[Ephemeral] \x1B[32mINFO: Running on port ${port} in ${devMode ? "dev" : "production"} mode
Configured with Masqr: ${masqr}
Configured with IP Leak Protection: ${noIpLeak}
`);
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@radix-ui/react-toast": "^1.1.5",
"@radix-ui/react-tooltip": "^1.0.7",
"@titaniumnetwork-dev/ultraviolet": "^3.0.0",
"@tomphttp/bare-server-node": "^2.0.3",
"@types/express": "^4.17.21",
"@types/react-router-dom": "^5.3.3",
"autoprefixer": "^10.4.19",
Expand Down
57 changes: 5 additions & 52 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 5 additions & 32 deletions public/sw.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
/*global UVServiceWorker importScripts __uv$config localforage */
/*global UVServiceWorker importScripts __uv$config */
importScripts("/epoxy/index.js");
importScripts("/libcurl/index.js");
importScripts("/uv/uv.bundle.js");
importScripts("/uv/uv.config.js");
importScripts("/uv/uv.sw.js");
importScripts("/localforage/localforage.min.js");
localforage.config({
driver: localforage.INDEXEDDB,
name: "ephemeral",
storeName: "__ephemeral_config",
});
const setUv = async () => {
try {
const bare =
(await localforage.getItem("proxy.bareServer")) ||
location.origin + "/bend/";
self.__uv$config.bare = bare;
self.uv = new UVServiceWorker(self.__uv$config);
} catch (error) {
console.error(
"\x1b[34;49;1m[Ephemeral] \x1B[31mERROR: Settings for Ultraviolet cannot be set (self.uv) " +
error,
);
}
};
const uv = new UVServiceWorker();
self.addEventListener("fetch", (event) => {
if (event.request.url.startsWith(location.origin + __uv$config.prefix)) {
event.respondWith(
(async () => {
await setUv().catch((error) => {
console.error(
"\x1b[34;49;1m[Ephemeral] \x1B[31mERROR: Settings for Ultraviolet cannot be set (event.respondWith) " +
error,
);
});
return await self.uv.fetch(event);
})(),
);
event.respondWith(uv.fetch(event));
}
});
2 changes: 1 addition & 1 deletion public/uv/uv.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const cipher = factory(key);

self.__uv$config = {
prefix: "/~/dark/",
bare: "/bend/",
bare: "https://gointerstellar.app/o/",
encodeUrl: cipher.enc,
decodeUrl: cipher.dec,
handler: "/uv/uv.handler.js",
Expand Down
Loading

0 comments on commit c565ff4

Please sign in to comment.