Feat: Rammerhead, See description

Currently can only be run with SSL
This commit is contained in:
MotorTruck1221 2024-10-06 03:52:01 -06:00
parent 3fd603667d
commit ce5c4e5345
No known key found for this signature in database
GPG key ID: 08F417E2B8B61EA4
2 changed files with 43 additions and 24 deletions

View file

@ -6,11 +6,19 @@ import express from "express";
import multer from "multer";
import { DataTypes, Sequelize } from "sequelize";
import wisp from "wisp-server-node";
import { createRammerhead, shouldRouteRh, routeRhUpgrade, routeRhRequest } from "@rubynetwork/rammerhead";
import { handler as ssrHandler } from "./dist/server/entry.mjs";
const config = JSON.parse(fs.readFileSync("config.json", "utf8"));
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
//create the rh server.
const rh = createRammerhead({
logLevel: 'debug',
reverseProxy: true,
disableLocalStorageSync: false,
disableHttp2: false
});
const app = express();
const publicPath = "dist/client";
const sequelize = new Sequelize("database", "user", "password", {
@ -312,11 +320,19 @@ const server = createServer();
server.on("request", (req, res) => {
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
if (shouldRouteRh(req)) {
routeRhRequest(rh, req, res);
}
else {
app(req, res);
}
});
server.on("upgrade", (req, socket, head) => {
if (req.url.endsWith("/wisp/")) {
if (shouldRouteRh(req)) {
routeRhUpgrade(rh, req, socket, head);
}
else if (req.url.endsWith("/wisp/")) {
wisp.routeRequest(req, socket, head);
}
});

View file

@ -50,6 +50,7 @@ const t = useTranslations(lang);
</Layout>
<script>
import { initSw, setTransport } from "@utils/registerSW.ts"; //../../utils/registerSW.ts
import { RammerheadEncode } from "@rubynetwork/rammerhead-browser";
import {
WispServerURLS,
SearchEngines,
@ -63,20 +64,13 @@ const t = useTranslations(lang);
type Suggestion = {
phrase: string;
};
function proxy(term: string) {
async function proxy(term: string) {
const searchEngine = localStorage.getItem(
Settings.ProxySettings.searchEngine
);
const proxy = localStorage.getItem(Settings.ProxySettings.proxy);
const proxySelection = localStorage.getItem(Settings.ProxySettings.proxy);
const openIn = localStorage.getItem(Settings.ProxySettings.openIn);
const proxyUrl =
__uv$config!.prefix +
__uv$config.encodeUrl!(
search(
term,
searchEngine ? SearchEngines[searchEngine] : SearchEngines.ddg
)
);
const proxyUrl = proxySelection === "uv" ? __uv$config!.prefix + __uv$config.encodeUrl!(search(term, searchEngine ? SearchEngines[searchEngine] : SearchEngines.ddg)) : await RammerheadEncode(search(term, searchEngine ? SearchEngines[searchEngine] : SearchEngines.ddg));
if (openIn === "a:b" || openIn === "blob") {
return cloak(
openIn as string,
@ -84,7 +78,7 @@ const t = useTranslations(lang);
`${window.location.origin}${proxyUrl}`
);
} else if (openIn === "direct") {
return (window.location.href = proxyUrl);
return (window.location.href = proxyUrl as string);
} else {
return proxyUrl;
}
@ -96,20 +90,29 @@ const t = useTranslations(lang);
const input = document.getElementById("nebula-input") as HTMLInputElement;
const iframe = document.getElementById("neb-iframe") as HTMLIFrameElement;
const omnibox = document.getElementById("omnibox") as HTMLDivElement;
input?.addEventListener("keypress", function (event: any) {
input?.addEventListener("keypress", async function (event: any) {
if (event.key === "Enter") {
if (localStorage.getItem(Settings.ProxySettings.proxy) === "uv") {
initSw().then(() => {
setTransport(
localStorage.getItem(Settings.ProxySettings.transport) as string
).then(() => {
).then(async () => {
iframe.classList.remove("hidden");
const url = proxy(input?.value);
const url = await proxy(input?.value);
if (url) {
iframe.src = url;
iframe.src = url as string;
}
});
});
}
else {
iframe.classList.remove("hidden");
const url = await proxy(input?.value);
if (url) {
iframe.src = "/" + url as string;
}
}
}
});
input?.addEventListener("input", async function () {
if (!libcurlClient) {