Skip to content

Commit

Permalink
STATIC PLEASE BE DONE
Browse files Browse the repository at this point in the history
  • Loading branch information
ArbYusuf authored Dec 25, 2023
1 parent 06fdfd1 commit 2a30600
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 7 deletions.
60 changes: 60 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import express from "express";
import http from "node:http";
import createBareServer from "@tomphttp/bare-server-node";
import path from "node:path";
import * as dotenv from "dotenv";
dotenv.config();

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

app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);

app.use(express.static(path.join(__dirname, "static")));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "static", "index.html"));
});
app.get("/science", (req, res) => {
res.sendFile(path.join(__dirname, "static", "apps.html"));
});
app.get("/math", (req, res) => {
res.sendFile(path.join(__dirname, "static", "games.html"));
});
app.get("/english", (req, res) => {
res.sendFile(path.join(__dirname, "static", "proxy.html"));
});
app.get("/settings", (req, res) => {
res.sendFile(path.join(__dirname, "static", "settings.html"));
});


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

server.on("upgrade", (req, socket, head) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeUpgrade(req, socket, head);
} else {
socket.end();
}
});

server.on("listening", () => {
console.log(`Snorlax's Cave listening on port 8080 ${process.env.PORT}`);
});

server.listen({
port: process.env.PORT,
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions assets/js/index.js → static/assets/js/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const form = document.querySelector('form');
const input = document.querySelector('input');
if(form) {

form.addEventListener('submit', async event => {
event.preventDefault();
window.navigator.serviceWorker.register('./sw.js', {
scope: uv$config.prefix
scope: __uv$config.prefix
}).then(() => {
let url = input.value.trim();
if (!isUrl(url)) url = 'https://www.google.com/search?q=' + url;
else if (!(url.startsWith('https://%27/) || url.startsWith('http://%27%29%29/) url = 'http://' + url;
window.location.href = uv$config.prefix + __uv$config.encodeUrl(url);
else if (!(url.startsWith('https://') || url.startsWith('http://'))) url = 'http://' + url;
window.location.href = __uv$config.prefix + __uv$config.encodeUrl(url);
});
});
}

function isUrl(val = "") {
if (
/^http(s?):///.test(val) ||
/^http(s?):\/\//.test(val) ||
(val.includes(".") && val.substr(0, 1) !== " ")
)
return true;
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion proxy.html → static/proxy.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1 style="font-size:33px;color:white;">Proxy</h1>
<br>
<input class="proxy" placeholder="Type URL or search query" style="color:white;"></input>
</form>
<script src="/assets/js/index.js"></script>
<script src="/assets/"></script>
<script src="/uv/uv.bundle.js"></script>
<script src="/uv/uv.config.js"></script>
<html>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 2a30600

Please sign in to comment.