Skip to content

Commit ef3fdc4

Browse files
committed
Optimizations and cleaning
1 parent 229b5c0 commit ef3fdc4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1332
-1401
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ RUN npm install
99

1010
COPY . .
1111

12-
CMD [ "node", "index.js" ]
12+
CMD [ "node", "index.js" ]

index.js

Lines changed: 59 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,85 @@
1-
import express from 'express'
2-
import basicAuth from 'express-basic-auth'
3-
import http from 'node:http'
4-
import { createBareServer } from '@tomphttp/bare-server-node'
5-
import path from 'node:path'
6-
import cors from 'cors'
7-
import config from './config.js'
8-
9-
const __dirname = process.cwd()
10-
const server = http.createServer()
11-
const app = express(server)
12-
const bareServer = createBareServer('/o/')
13-
const PORT = process.env.PORT || 8080
1+
import express from "express";
2+
import basicAuth from "express-basic-auth";
3+
import http from "node:http";
4+
import { createBareServer } from "@tomphttp/bare-server-node";
5+
import path from "node:path";
6+
import cors from "cors";
7+
import config from "./config.js";
8+
9+
const __dirname = process.cwd();
10+
const server = http.createServer();
11+
const app = express(server);
12+
const bareServer = createBareServer("/o/");
13+
const PORT = process.env.PORT || 8080;
1414

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

1919
app.use(
2020
basicAuth({
2121
users: config.users,
2222
challenge: true,
2323
})
24-
)
24+
);
2525
}
2626

27-
app.use(express.json())
28-
app.use(express.urlencoded({ extended: true }))
29-
app.use(cors())
30-
app.use(express.static(path.join(__dirname, 'static')))
27+
app.use(express.json());
28+
app.use(express.urlencoded({ extended: true }));
29+
app.use(cors());
30+
app.use(express.static(path.join(__dirname, "static")));
3131

3232
if (config.routes !== false) {
3333
const routes = [
34-
{ path: '/ap', file: 'apps.html' },
35-
{ path: '/g', file: 'games.html' },
36-
{ path: '/s', file: 'settings.html' },
37-
{ path: '/t', file: 'tabs.html' },
38-
{ path: '/p', file: 'go.html' },
39-
{ path: '/', file: 'index.html' },
40-
{ path: '/tos', file: 'tos.html' },
41-
]
34+
{ path: "/ap", file: "apps.html" },
35+
{ path: "/g", file: "games.html" },
36+
{ path: "/s", file: "settings.html" },
37+
{ path: "/t", file: "tabs.html" },
38+
{ path: "/p", file: "go.html" },
39+
{ path: "/", file: "index.html" },
40+
{ path: "/tos", file: "tos.html" },
41+
];
4242

4343
routes.forEach((route) => {
4444
app.get(route.path, (req, res) => {
45-
res.sendFile(path.join(__dirname, 'static', route.file))
46-
})
47-
})
45+
res.sendFile(path.join(__dirname, "static", route.file));
46+
});
47+
});
4848
}
4949

5050
if (config.local !== false) {
51-
app.get('/e/*', (req, res, next) => {
52-
const baseUrls = [
53-
'https://raw.githubusercontent.com/v-5x/x/fixy',
54-
'https://raw.githubusercontent.com/ypxa/y/main',
55-
'https://raw.githubusercontent.com/ypxa/w/master',
56-
]
57-
fetchData(req, res, next, baseUrls)
58-
})
51+
app.get("/e/*", (req, res, next) => {
52+
const baseUrls = ["https://raw.githubusercontent.com/v-5x/x/fixy", "https://raw.githubusercontent.com/ypxa/y/main", "https://raw.githubusercontent.com/ypxa/w/master"];
53+
fetchData(req, res, next, baseUrls);
54+
});
5955
}
6056

6157
const fetchData = async (req, res, next, baseUrls) => {
6258
try {
63-
const reqTarget = baseUrls.map((baseUrl) => `${baseUrl}/${req.params[0]}`)
64-
let data
65-
let asset
59+
const reqTarget = baseUrls.map((baseUrl) => `${baseUrl}/${req.params[0]}`);
60+
let data;
61+
let asset;
6662

6763
for (const target of reqTarget) {
68-
asset = await fetch(target)
64+
asset = await fetch(target);
6965
if (asset.ok) {
70-
data = await asset.arrayBuffer()
71-
break
66+
data = await asset.arrayBuffer();
67+
break;
7268
}
7369
}
7470

7571
if (data) {
76-
res.end(Buffer.from(data))
72+
res.end(Buffer.from(data));
7773
} else {
78-
res.status(404).send()
74+
res.status(404).send();
7975
}
8076
} catch (error) {
81-
console.error(`Error fetching ${req.url}:`, error)
82-
res.status(500).send()
77+
console.error(`Error fetching ${req.url}:`, error);
78+
res.status(500).send();
8379
}
84-
}
80+
};
8581

86-
app.get('*', (req, res) => {
82+
app.get("*", (req, res) => {
8783
res.status(404).send();
8884
});
8985

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

95-
server.on('request', (req, res) => {
91+
server.on("request", (req, res) => {
9692
if (bareServer.shouldRoute(req)) {
97-
bareServer.routeRequest(req, res)
93+
bareServer.routeRequest(req, res);
9894
} else {
99-
app(req, res)
95+
app(req, res);
10096
}
101-
})
97+
});
10298

103-
server.on('upgrade', (req, socket, head) => {
99+
server.on("upgrade", (req, socket, head) => {
104100
if (bareServer.shouldRoute(req)) {
105-
bareServer.routeUpgrade(req, socket, head)
101+
bareServer.routeUpgrade(req, socket, head);
106102
} else {
107-
socket.end()
103+
socket.end();
108104
}
109-
})
105+
});
110106

111-
server.on('listening', () => {
112-
console.log(`Running at http://localhost:${PORT}`)
113-
})
107+
server.on("listening", () => {
108+
console.log(`Running at http://localhost:${PORT}`);
109+
});
114110

115111
server.listen({
116112
port: PORT,
117-
})
113+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
"devDependencies": {
2323
"prettier": "3.2.5"
2424
}
25-
}
25+
}

static/apps.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!doctype html>
1+
<!DOCTYPE html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
@@ -42,15 +42,15 @@
4242
<script async src="https://www.googletagmanager.com/gtag/js?id=G-WKJQ5QHQTJ"></script>
4343
<!-- DO NOT REMOVE-->
4444
<script>
45-
window.dataLayer = window.dataLayer || []
45+
window.dataLayer = window.dataLayer || [];
4646
function gtag() {
47-
dataLayer.push(arguments)
47+
dataLayer.push(arguments);
4848
}
49-
gtag('js', new Date())
49+
gtag("js", new Date());
5050

51-
gtag('config', 'G-WKJQ5QHQTJ')
51+
gtag("config", "G-WKJQ5QHQTJ");
5252
</script>
5353
<!-- DO NOT REMOVE-->
5454
<div id="adv"></div>
5555
</body>
56-
</html>
56+
</html>

static/assets/json/a.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,4 @@
349349
"categories": ["all"],
350350
"error": "true"
351351
}
352-
]
352+
]
-3.33 KB
Loading
-873 KB
Loading
-46 Bytes
Loading
-152 Bytes
Loading
-169 KB
Loading

0 commit comments

Comments
 (0)