Feat: Rammerhead, See description
Currently can only be run with SSL
This commit is contained in:
parent
3fd603667d
commit
ce5c4e5345
2 changed files with 43 additions and 24 deletions
20
server.js
20
server.js
|
|
@ -6,11 +6,19 @@ import express from "express";
|
||||||
import multer from "multer";
|
import multer from "multer";
|
||||||
import { DataTypes, Sequelize } from "sequelize";
|
import { DataTypes, Sequelize } from "sequelize";
|
||||||
import wisp from "wisp-server-node";
|
import wisp from "wisp-server-node";
|
||||||
|
import { createRammerhead, shouldRouteRh, routeRhUpgrade, routeRhRequest } from "@rubynetwork/rammerhead";
|
||||||
import { handler as ssrHandler } from "./dist/server/entry.mjs";
|
import { handler as ssrHandler } from "./dist/server/entry.mjs";
|
||||||
|
|
||||||
const config = JSON.parse(fs.readFileSync("config.json", "utf8"));
|
const config = JSON.parse(fs.readFileSync("config.json", "utf8"));
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
//create the rh server.
|
||||||
|
const rh = createRammerhead({
|
||||||
|
logLevel: 'debug',
|
||||||
|
reverseProxy: true,
|
||||||
|
disableLocalStorageSync: false,
|
||||||
|
disableHttp2: false
|
||||||
|
});
|
||||||
const app = express();
|
const app = express();
|
||||||
const publicPath = "dist/client";
|
const publicPath = "dist/client";
|
||||||
const sequelize = new Sequelize("database", "user", "password", {
|
const sequelize = new Sequelize("database", "user", "password", {
|
||||||
|
|
@ -312,11 +320,19 @@ const server = createServer();
|
||||||
server.on("request", (req, res) => {
|
server.on("request", (req, res) => {
|
||||||
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
|
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
|
||||||
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
|
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
|
||||||
app(req, res);
|
if (shouldRouteRh(req)) {
|
||||||
|
routeRhRequest(rh, req, res);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
app(req, res);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("upgrade", (req, socket, head) => {
|
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);
|
wisp.routeRequest(req, socket, head);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ const t = useTranslations(lang);
|
||||||
</Layout>
|
</Layout>
|
||||||
<script>
|
<script>
|
||||||
import { initSw, setTransport } from "@utils/registerSW.ts"; //../../utils/registerSW.ts
|
import { initSw, setTransport } from "@utils/registerSW.ts"; //../../utils/registerSW.ts
|
||||||
|
import { RammerheadEncode } from "@rubynetwork/rammerhead-browser";
|
||||||
import {
|
import {
|
||||||
WispServerURLS,
|
WispServerURLS,
|
||||||
SearchEngines,
|
SearchEngines,
|
||||||
|
|
@ -63,20 +64,13 @@ const t = useTranslations(lang);
|
||||||
type Suggestion = {
|
type Suggestion = {
|
||||||
phrase: string;
|
phrase: string;
|
||||||
};
|
};
|
||||||
function proxy(term: string) {
|
async function proxy(term: string) {
|
||||||
const searchEngine = localStorage.getItem(
|
const searchEngine = localStorage.getItem(
|
||||||
Settings.ProxySettings.searchEngine
|
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 openIn = localStorage.getItem(Settings.ProxySettings.openIn);
|
||||||
const proxyUrl =
|
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));
|
||||||
__uv$config!.prefix +
|
|
||||||
__uv$config.encodeUrl!(
|
|
||||||
search(
|
|
||||||
term,
|
|
||||||
searchEngine ? SearchEngines[searchEngine] : SearchEngines.ddg
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if (openIn === "a:b" || openIn === "blob") {
|
if (openIn === "a:b" || openIn === "blob") {
|
||||||
return cloak(
|
return cloak(
|
||||||
openIn as string,
|
openIn as string,
|
||||||
|
|
@ -84,7 +78,7 @@ const t = useTranslations(lang);
|
||||||
`${window.location.origin}${proxyUrl}`
|
`${window.location.origin}${proxyUrl}`
|
||||||
);
|
);
|
||||||
} else if (openIn === "direct") {
|
} else if (openIn === "direct") {
|
||||||
return (window.location.href = proxyUrl);
|
return (window.location.href = proxyUrl as string);
|
||||||
} else {
|
} else {
|
||||||
return proxyUrl;
|
return proxyUrl;
|
||||||
}
|
}
|
||||||
|
|
@ -96,19 +90,28 @@ const t = useTranslations(lang);
|
||||||
const input = document.getElementById("nebula-input") as HTMLInputElement;
|
const input = document.getElementById("nebula-input") as HTMLInputElement;
|
||||||
const iframe = document.getElementById("neb-iframe") as HTMLIFrameElement;
|
const iframe = document.getElementById("neb-iframe") as HTMLIFrameElement;
|
||||||
const omnibox = document.getElementById("omnibox") as HTMLDivElement;
|
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 (event.key === "Enter") {
|
||||||
initSw().then(() => {
|
if (localStorage.getItem(Settings.ProxySettings.proxy) === "uv") {
|
||||||
setTransport(
|
initSw().then(() => {
|
||||||
localStorage.getItem(Settings.ProxySettings.transport) as string
|
setTransport(
|
||||||
).then(() => {
|
localStorage.getItem(Settings.ProxySettings.transport) as string
|
||||||
iframe.classList.remove("hidden");
|
).then(async () => {
|
||||||
const url = proxy(input?.value);
|
iframe.classList.remove("hidden");
|
||||||
if (url) {
|
const url = await proxy(input?.value);
|
||||||
iframe.src = url;
|
if (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 () {
|
input?.addEventListener("input", async function () {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue