Add /search endpoint, working on impl.

This commit is contained in:
wearrrrr 2024-02-20 10:06:46 -06:00
parent 585f937b81
commit a9a75b9280
6 changed files with 90 additions and 97 deletions

View file

@ -14,7 +14,6 @@ dotenv.config();
if (!existsSync("./dist")) build(); if (!existsSync("./dist")) build();
const PORT = process.env.PORT || 3000; const PORT = process.env.PORT || 3000;
const SITE_URL = process.env.URL || "http://0.0.0.0";
const bare = createBareServer("/bare/"); const bare = createBareServer("/bare/");
console.log(chalk.gray("Starting Bare...")); console.log(chalk.gray("Starting Bare..."));
@ -41,10 +40,9 @@ const rammerheadScopes = [
]; ];
const rammerheadSession = /^\/[a-z0-9]{32}/; const rammerheadSession = /^\/[a-z0-9]{32}/;
const rh_path = "node_modules/rammerhead/src/client";
function shouldRouteRh(req) { function shouldRouteRh(req) {
const url = new URL(req.url, SITE_URL); const url = new URL(req.url, 'http://0.0.0.0');
return rammerheadScopes.includes(url.pathname) || rammerheadSession.test(url.pathname); return rammerheadScopes.includes(url.pathname) || rammerheadSession.test(url.pathname);
} }
@ -82,7 +80,6 @@ app.use(compression());
app.use(express.static(path.join(process.cwd(), "static"))); app.use(express.static(path.join(process.cwd(), "static")));
app.use(express.static(path.join(process.cwd(), "build"))); app.use(express.static(path.join(process.cwd(), "build")));
app.use("/uv/", express.static(uvPath)); app.use("/uv/", express.static(uvPath));
app.use("/", express.static(rh_path));
app.use(express.json()); app.use(express.json());
app.use( app.use(
express.urlencoded({ express.urlencoded({
@ -90,6 +87,23 @@ app.use(
}) })
); );
app.use("/", express.static("dist/client/")); app.use("/", express.static("dist/client/"));
app.get("/search", async (req, res) => {
try {
const { query } = req.query;
const response = await fetch(
`http://api.duckduckgo.com/ac?q=${query}&format=json`
).then((apiRes) => apiRes.json());
res.send(response);
} catch (err) {
res.redirect(302, "/404.html");
}
});
app.get('*', function(req, res){
res.redirect(302, '/404.html');
});
console.log(chalk.gray("Starting Alu...")); console.log(chalk.gray("Starting Alu..."));
console.log(chalk.green("Alu started successfully!")); console.log(chalk.green("Alu started successfully!"));

121
package-lock.json generated
View file

@ -10,9 +10,9 @@
"dependencies": { "dependencies": {
"@astrojs/check": "^0.4.0", "@astrojs/check": "^0.4.0",
"@astrojs/node": "^7.0.4", "@astrojs/node": "^7.0.4",
"@nebula-services/ultraviolet": "^1.0.1-1.patch.5", "@nebula-services/ultraviolet": "^1.0.1-1.patch.7",
"@tomphttp/bare-server-node": "^2.0.1", "@tomphttp/bare-server-node": "^2.0.1",
"astro": "^4.3.3", "astro": "^4.4.1",
"astro-i18n": "^2.2.4", "astro-i18n": "^2.2.4",
"astro-i18next": "^1.0.0-beta.21", "astro-i18next": "^1.0.0-beta.21",
"chalk": "^5.3.0", "chalk": "^5.3.0",
@ -973,14 +973,25 @@
"@jridgewell/sourcemap-codec": "^1.4.14" "@jridgewell/sourcemap-codec": "^1.4.14"
} }
}, },
"node_modules/@medv/finder": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/@medv/finder/-/finder-3.1.0.tgz",
"integrity": "sha512-ojkXjR3K0Zz3jnCR80tqPL+0yvbZk/lEodb6RIVjLz7W8RVA2wrw8ym/CzCpXO9SYVUIKHFUpc7jvf8UKfIM3w=="
},
"node_modules/@nebula-services/bare-client": {
"version": "1.1.2-beta.3-patch.1",
"resolved": "https://registry.npmjs.org/@nebula-services/bare-client/-/bare-client-1.1.2-beta.3-patch.1.tgz",
"integrity": "sha512-SgXCJruqgFg9ulgKd/S+6IAL3G5lP08Ey+pLLv768pwvgV5WgXdoWxytV1jJ8kd0vpQcnrq3ropTn2buT+8r5Q=="
},
"node_modules/@nebula-services/ultraviolet": { "node_modules/@nebula-services/ultraviolet": {
"version": "1.0.1-1.patch.5", "version": "1.0.1-1.patch.7",
"resolved": "https://registry.npmjs.org/@nebula-services/ultraviolet/-/ultraviolet-1.0.1-1.patch.5.tgz", "resolved": "https://registry.npmjs.org/@nebula-services/ultraviolet/-/ultraviolet-1.0.1-1.patch.7.tgz",
"integrity": "sha512-EDwbh+AXPg+JxPcPhRHJh6crLh1AHSodcAgfO47ug4paoLkWXE0ELU5Tm0Um38kguTBHzTOPFSzNULpaFbhFLw==", "integrity": "sha512-9xe7BR1DbxtK+TeAlsllbuDE6j+eA9rMFQp4M05vkHjO5CuQYUFfC48m/y4vWhbna6Uf2xdlZLJr6gYGDJStBA==",
"dependencies": { "dependencies": {
"@tomphttp/bare-client": "^1.1.2-beta.3", "@nebula-services/bare-client": "^1.1.2-beta.3-patch.1",
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"css-tree": "^2.0.4", "css-tree": "^2.0.4",
"esbuild": "^0.19.11",
"esotope-hammerhead": "^0.6.1", "esotope-hammerhead": "^0.6.1",
"events": "^3.3.0", "events": "^3.3.0",
"idb": "^7.1.1", "idb": "^7.1.1",
@ -990,11 +1001,6 @@
"set-cookie-parser": "^2.4.8" "set-cookie-parser": "^2.4.8"
} }
}, },
"node_modules/@nebula-services/ultraviolet/node_modules/@tomphttp/bare-client": {
"version": "1.1.2-beta.3",
"resolved": "https://registry.npmjs.org/@tomphttp/bare-client/-/bare-client-1.1.2-beta.3.tgz",
"integrity": "sha512-WyIVnSAqzfrLejmOhh/l/LtDOeK+SHnBGi/z+QyliVP1T1JxoNE5eecwxlV+osM9J6FTAYVGNHr8/5bubaIj6Q=="
},
"node_modules/@nodelib/fs.scandir": { "node_modules/@nodelib/fs.scandir": {
"version": "2.1.5", "version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@ -1727,9 +1733,9 @@
} }
}, },
"node_modules/astro": { "node_modules/astro": {
"version": "4.3.3", "version": "4.4.1",
"resolved": "https://registry.npmjs.org/astro/-/astro-4.3.3.tgz", "resolved": "https://registry.npmjs.org/astro/-/astro-4.4.1.tgz",
"integrity": "sha512-8Vfcv8LuCfzkLj+NMk7i7pu5o0MPyDkYqUYWELSwKxWf85zJSNU4oLg4DlEZWbVpm5LeTfVrpSGrZGy5n4grBg==", "integrity": "sha512-nJLgNg8UXKBJYXjWtekgv1TYZES++LAdShgyKL8L5yJMeiqlDSO+/Laq5VfRKoL9hzBdyolJMB0WDE/+bRZytg==",
"dependencies": { "dependencies": {
"@astrojs/compiler": "^2.5.3", "@astrojs/compiler": "^2.5.3",
"@astrojs/internal-helpers": "0.2.1", "@astrojs/internal-helpers": "0.2.1",
@ -1741,6 +1747,7 @@
"@babel/plugin-transform-react-jsx": "^7.22.5", "@babel/plugin-transform-react-jsx": "^7.22.5",
"@babel/traverse": "^7.23.3", "@babel/traverse": "^7.23.3",
"@babel/types": "^7.23.3", "@babel/types": "^7.23.3",
"@medv/finder": "^3.1.0",
"@types/babel__core": "^7.20.4", "@types/babel__core": "^7.20.4",
"acorn": "^8.11.2", "acorn": "^8.11.2",
"aria-query": "^5.3.0", "aria-query": "^5.3.0",
@ -1778,19 +1785,18 @@
"p-queue": "^8.0.1", "p-queue": "^8.0.1",
"path-to-regexp": "^6.2.1", "path-to-regexp": "^6.2.1",
"preferred-pm": "^3.1.2", "preferred-pm": "^3.1.2",
"probe-image-size": "^7.2.3",
"prompts": "^2.4.2", "prompts": "^2.4.2",
"rehype": "^13.0.1", "rehype": "^13.0.1",
"resolve": "^1.22.4", "resolve": "^1.22.4",
"semver": "^7.5.4", "semver": "^7.5.4",
"server-destroy": "^1.0.1", "shikiji": "^0.9.19",
"shikiji": "^0.9.18", "shikiji-core": "^0.9.19",
"string-width": "^7.0.0", "string-width": "^7.0.0",
"strip-ansi": "^7.1.0", "strip-ansi": "^7.1.0",
"tsconfck": "^3.0.0", "tsconfck": "^3.0.0",
"unist-util-visit": "^5.0.0", "unist-util-visit": "^5.0.0",
"vfile": "^6.0.1", "vfile": "^6.0.1",
"vite": "^5.0.12", "vite": "^5.1.2",
"vitefu": "^0.2.5", "vitefu": "^0.2.5",
"which-pm": "^2.1.1", "which-pm": "^2.1.1",
"yargs-parser": "^21.1.1", "yargs-parser": "^21.1.1",
@ -4715,11 +4721,6 @@
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
}, },
"node_modules/lodash.merge": {
"version": "4.6.2",
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
"integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ=="
},
"node_modules/log-symbols": { "node_modules/log-symbols": {
"version": "5.1.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-5.1.0.tgz", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-5.1.0.tgz",
@ -5868,30 +5869,6 @@
"resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz", "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz",
"integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==" "integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg=="
}, },
"node_modules/needle": {
"version": "2.9.1",
"resolved": "https://registry.npmjs.org/needle/-/needle-2.9.1.tgz",
"integrity": "sha512-6R9fqJ5Zcmf+uYaFgdIHmLwNldn5HbK8L5ybn7Uz+ylX/rnOsSp1AHcvQSrCaFN+qNM1wpymHqD7mVasEOlHGQ==",
"dependencies": {
"debug": "^3.2.6",
"iconv-lite": "^0.4.4",
"sax": "^1.2.4"
},
"bin": {
"needle": "bin/needle"
},
"engines": {
"node": ">= 4.4.x"
}
},
"node_modules/needle/node_modules/debug": {
"version": "3.2.7",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
"dependencies": {
"ms": "^2.1.1"
}
},
"node_modules/negotiator": { "node_modules/negotiator": {
"version": "0.6.3", "version": "0.6.3",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
@ -9143,9 +9120,9 @@
} }
}, },
"node_modules/postcss": { "node_modules/postcss": {
"version": "8.4.33", "version": "8.4.35",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.33.tgz", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.35.tgz",
"integrity": "sha512-Kkpbhhdjw2qQs2O2DGX+8m5OVqEcbB9HRBvuYM9pgrjEFUg30A9LmXNlTAUj4S9kgtGyrMbTzVjH7E+s5Re2yg==", "integrity": "sha512-u5U8qYpBCpN13BsiEB0CbR1Hhh4Gc0zLFuedrHJKMctHCHAGrMdG0PRM/KErzAL3CU6/eckEtmHNB3x6e3c0vA==",
"funding": [ "funding": [
{ {
"type": "opencollective", "type": "opencollective",
@ -9322,16 +9299,6 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/probe-image-size": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/probe-image-size/-/probe-image-size-7.2.3.tgz",
"integrity": "sha512-HubhG4Rb2UH8YtV4ba0Vp5bQ7L78RTONYu/ujmCu5nBI8wGv24s4E9xSKBi0N1MowRpxk76pFCpJtW0KPzOK0w==",
"dependencies": {
"lodash.merge": "^4.6.2",
"needle": "^2.5.2",
"stream-parser": "~0.3.1"
}
},
"node_modules/process": { "node_modules/process": {
"version": "0.11.10", "version": "0.11.10",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
@ -10257,11 +10224,6 @@
"suf-log": "^2.5.3" "suf-log": "^2.5.3"
} }
}, },
"node_modules/sax": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.3.0.tgz",
"integrity": "sha512-0s+oAmw9zLl1V1cS9BtZN7JAd0cW5e0QH4W3LWEK6a4LaLEA2OTpGYWDY+6XasBLtz6wkm3u1xRw95mRuJ59WA=="
},
"node_modules/section-matter": { "node_modules/section-matter": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/section-matter/-/section-matter-1.0.0.tgz", "resolved": "https://registry.npmjs.org/section-matter/-/section-matter-1.0.0.tgz",
@ -10707,27 +10669,6 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/stream-parser": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/stream-parser/-/stream-parser-0.3.1.tgz",
"integrity": "sha512-bJ/HgKq41nlKvlhccD5kaCr/P+Hu0wPNKPJOH7en+YrJu/9EgqUF+88w5Jb6KNcjOFMhfX4B2asfeAtIGuHObQ==",
"dependencies": {
"debug": "2"
}
},
"node_modules/stream-parser/node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dependencies": {
"ms": "2.0.0"
}
},
"node_modules/stream-parser/node_modules/ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
},
"node_modules/streamx": { "node_modules/streamx": {
"version": "2.15.7", "version": "2.15.7",
"resolved": "https://registry.npmjs.org/streamx/-/streamx-2.15.7.tgz", "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.15.7.tgz",
@ -11595,12 +11536,12 @@
} }
}, },
"node_modules/vite": { "node_modules/vite": {
"version": "5.0.12", "version": "5.1.3",
"resolved": "https://registry.npmjs.org/vite/-/vite-5.0.12.tgz", "resolved": "https://registry.npmjs.org/vite/-/vite-5.1.3.tgz",
"integrity": "sha512-4hsnEkG3q0N4Tzf1+t6NdN9dg/L3BM+q8SWgbSPnJvrgH2kgdyzfVJwbR1ic69/4uMJJ/3dqDZZE5/WwqW8U1w==", "integrity": "sha512-UfmUD36DKkqhi/F75RrxvPpry+9+tTkrXfMNZD+SboZqBCMsxKtO52XeGzzuh7ioz+Eo/SYDBbdb0Z7vgcDJew==",
"dependencies": { "dependencies": {
"esbuild": "^0.19.3", "esbuild": "^0.19.3",
"postcss": "^8.4.32", "postcss": "^8.4.35",
"rollup": "^4.2.0" "rollup": "^4.2.0"
}, },
"bin": { "bin": {

View file

@ -13,7 +13,7 @@
"@astrojs/node": "^7.0.4", "@astrojs/node": "^7.0.4",
"@nebula-services/ultraviolet": "^1.0.1-1.patch.7", "@nebula-services/ultraviolet": "^1.0.1-1.patch.7",
"@tomphttp/bare-server-node": "^2.0.1", "@tomphttp/bare-server-node": "^2.0.1",
"astro": "^4.3.3", "astro": "^4.4.1",
"astro-i18n": "^2.2.4", "astro-i18n": "^2.2.4",
"astro-i18next": "^1.0.0-beta.21", "astro-i18next": "^1.0.0-beta.21",
"chalk": "^5.3.0", "chalk": "^5.3.0",

View file

@ -13,4 +13,11 @@ import Layout from "../layouts/Layout.astro";
.error-page { .error-page {
color: white; color: white;
} }
.main-content {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height: 100%;
}
</style> </style>

View file

@ -16,7 +16,7 @@ export function getStaticPaths() {
<h1 class="title-text">{t("menu.welcome")}</h1> <h1 class="title-text">{t("menu.welcome")}</h1>
<div class="form-wrapper"> <div class="form-wrapper">
<form class="url-input-form" id="url-input-form"> <form class="url-input-form" id="url-input-form">
<input class="url-input" type="text" placeholder={t("menu.search")} /> <input class="url-input" id="url-input" type="text" placeholder={t("menu.search")} />
<div id="loading-content">Loading...</div> <div id="loading-content">Loading...</div>
<div id="top-bar"></div> <div id="top-bar"></div>
<iframe title="proxy-iframe" id="proxy-frame"></iframe> <iframe title="proxy-iframe" id="proxy-frame"></iframe>
@ -36,7 +36,8 @@ export function getStaticPaths() {
<h2>How can I contribute to the development of Alu?</h2> <h2>How can I contribute to the development of Alu?</h2>
<p> <p>
Spreading the word of Alu is a great start, but if you really enjoy Alu, and want private Spreading the word of Alu is a great start, but if you really enjoy Alu, and want private
links, consider supporting me through Patreon! You can support me <Link links, consider supporting me through Patreon! You can support me
<Link
href="https://www.patreon.com/wearr/membership" href="https://www.patreon.com/wearr/membership"
newTab newTab
linkTextContent="Here!" linkTextContent="Here!"
@ -47,6 +48,35 @@ export function getStaticPaths() {
</div> </div>
</Layout> </Layout>
<script>
const debounce = (func, delay) => {
let debounceTimer;
return function () {
const context = this;
const args = arguments;
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
func.apply(context, args);
}, delay);
};
};
const urlInput = document.getElementById("url-input");
async function sendAPIRequest() {
let url = urlInput.value;
let request = await fetch("https://api.duckduckgo.com/?q=" + url + "&format=json");
let data = await request.json();
console.log(data);
}
const debouncedSendAPIRequest = debounce(sendAPIRequest, 500);
urlInput.addEventListener("keyup", () => {
debouncedSendAPIRequest();
});
</script>
<style> <style>
.main-content { .main-content {
width: 100%; width: 100%;

View file

@ -1,5 +1,6 @@
{ {
"extends": "astro/tsconfigs/strict", "extends": "astro/tsconfigs/strict",
"exclude": ["node_modules/**"],
"compilerOptions": { "compilerOptions": {
"verbatimModuleSyntax": false, "verbatimModuleSyntax": false,
} }