Skip to content

Commit

Permalink
Optimizations and cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
3kh0 committed Apr 23, 2024
1 parent 229b5c0 commit ef3fdc4
Show file tree
Hide file tree
Showing 65 changed files with 1,332 additions and 1,401 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ RUN npm install

COPY . .

CMD [ "node", "index.js" ]
CMD [ "node", "index.js" ]
122 changes: 59 additions & 63 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,85 @@
import express from 'express'
import basicAuth from 'express-basic-auth'
import http from 'node:http'
import { createBareServer } from '@tomphttp/bare-server-node'
import path from 'node:path'
import cors from 'cors'
import config from './config.js'

const __dirname = process.cwd()
const server = http.createServer()
const app = express(server)
const bareServer = createBareServer('/o/')
const PORT = process.env.PORT || 8080
import express from "express";
import basicAuth from "express-basic-auth";
import http from "node:http";
import { createBareServer } from "@tomphttp/bare-server-node";
import path from "node:path";
import cors from "cors";
import config from "./config.js";

const __dirname = process.cwd();
const server = http.createServer();
const app = express(server);
const bareServer = createBareServer("/o/");
const PORT = process.env.PORT || 8080;

if (config.challenge) {
console.log('Password protection is enabled. Usernames are: ' + Object.keys(config.users))
console.log('Passwords are: ' + Object.values(config.users))
console.log("Password protection is enabled. Usernames are: " + Object.keys(config.users));
console.log("Passwords are: " + Object.values(config.users));

app.use(
basicAuth({
users: config.users,
challenge: true,
})
)
);
}

app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(cors())
app.use(express.static(path.join(__dirname, 'static')))
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.use(express.static(path.join(__dirname, "static")));

if (config.routes !== false) {
const routes = [
{ path: '/ap', file: 'apps.html' },
{ path: '/g', file: 'games.html' },
{ path: '/s', file: 'settings.html' },
{ path: '/t', file: 'tabs.html' },
{ path: '/p', file: 'go.html' },
{ path: '/', file: 'index.html' },
{ path: '/tos', file: 'tos.html' },
]
{ path: "/ap", file: "apps.html" },
{ path: "/g", file: "games.html" },
{ path: "/s", file: "settings.html" },
{ path: "/t", file: "tabs.html" },
{ path: "/p", file: "go.html" },
{ path: "/", file: "index.html" },
{ path: "/tos", file: "tos.html" },
];

routes.forEach((route) => {
app.get(route.path, (req, res) => {
res.sendFile(path.join(__dirname, 'static', route.file))
})
})
res.sendFile(path.join(__dirname, "static", route.file));
});
});
}

if (config.local !== false) {
app.get('/e/*', (req, res, next) => {
const baseUrls = [
'https://raw.githubusercontent.com/v-5x/x/fixy',
'https://raw.githubusercontent.com/ypxa/y/main',
'https://raw.githubusercontent.com/ypxa/w/master',
]
fetchData(req, res, next, baseUrls)
})
app.get("/e/*", (req, res, next) => {
const baseUrls = ["https://raw.githubusercontent.com/v-5x/x/fixy", "https://raw.githubusercontent.com/ypxa/y/main", "https://raw.githubusercontent.com/ypxa/w/master"];
fetchData(req, res, next, baseUrls);
});
}

const fetchData = async (req, res, next, baseUrls) => {
try {
const reqTarget = baseUrls.map((baseUrl) => `${baseUrl}/${req.params[0]}`)
let data
let asset
const reqTarget = baseUrls.map((baseUrl) => `${baseUrl}/${req.params[0]}`);
let data;
let asset;

for (const target of reqTarget) {
asset = await fetch(target)
asset = await fetch(target);
if (asset.ok) {
data = await asset.arrayBuffer()
break
data = await asset.arrayBuffer();
break;
}
}

if (data) {
res.end(Buffer.from(data))
res.end(Buffer.from(data));
} else {
res.status(404).send()
res.status(404).send();
}
} catch (error) {
console.error(`Error fetching ${req.url}:`, error)
res.status(500).send()
console.error(`Error fetching ${req.url}:`, error);
res.status(500).send();
}
}
};

app.get('*', (req, res) => {
app.get("*", (req, res) => {
res.status(404).send();
});

Expand All @@ -92,26 +88,26 @@ app.use((err, req, res, next) => {
res.status(500).send();
});

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

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

server.on('listening', () => {
console.log(`Running at http://localhost:${PORT}`)
})
server.on("listening", () => {
console.log(`Running at http://localhost:${PORT}`);
});

server.listen({
port: PORT,
})
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
"devDependencies": {
"prettier": "3.2.5"
}
}
}
12 changes: 6 additions & 6 deletions static/apps.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down Expand Up @@ -42,15 +42,15 @@
<script async src="https://www.googletagmanager.com/gtag/js?id=G-WKJQ5QHQTJ"></script>
<!-- DO NOT REMOVE-->
<script>
window.dataLayer = window.dataLayer || []
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments)
dataLayer.push(arguments);
}
gtag('js', new Date())
gtag("js", new Date());

gtag('config', 'G-WKJQ5QHQTJ')
gtag("config", "G-WKJQ5QHQTJ");
</script>
<!-- DO NOT REMOVE-->
<div id="adv"></div>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion static/assets/json/a.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,4 @@
"categories": ["all"],
"error": "true"
}
]
]
Binary file modified static/assets/media/background/full2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/background/wallpaper.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/britannica.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/campus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/canvas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/classlink-login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/classroom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/clever.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/deltamath.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/drive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/ducksters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/edpuzzle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/gmail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/goguardian-lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/goguardian.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/google-meet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/google.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/googleforms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/ixl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/kami.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/khan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/main_inverted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/minga.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/media/favicon/nearpod.png
Binary file modified static/assets/media/favicon/newsela.png
Binary file modified static/assets/media/favicon/noredink.webp
Binary file not shown.
Binary file modified static/assets/media/favicon/powerschool.png
Binary file modified static/assets/media/favicon/schoology.png
Binary file modified static/assets/media/favicon/worldhistoryencyclopedia.png
Loading

0 comments on commit ef3fdc4

Please sign in to comment.