Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
QuiteAFancyEmerald
GitHub Repository: QuiteAFancyEmerald/Holy-Unblocker
Path: blob/master/src/routes.mjs
11148 views
1
import { readFileSync } from 'node:fs';
2
import ecosystem from '../ecosystem.config.js';
3
4
// For toggling SEO display and more, see the config.json file.
5
const config = Object.freeze(
6
JSON.parse(readFileSync(new URL('../config.json', import.meta.url)))
7
);
8
9
const ecosystemConfig = Object.freeze(
10
ecosystem.apps.find((app) => app.name === 'HolyUB') || ecosystem.apps[0]
11
);
12
13
/* Record the server's location as a URL object, including its host and port.
14
* The host can be modified at /src/config.json, whereas the ports can be modified
15
* at /ecosystem.config.js.
16
*/
17
const serverUrl = ((base) => {
18
try {
19
base = new URL(config.host);
20
} catch (e) {
21
base = new URL('http://a');
22
base.host = config.host;
23
}
24
base.port =
25
ecosystemConfig[config.production ? 'env_production' : 'env'].PORT;
26
base.pathname =
27
(config.pathname || '/').replace(/\/+$|[^\w\/\.-]+/g, '') + '/';
28
return Object.freeze(base);
29
})();
30
31
let pages = {
32
/* If you are trying to add pages or assets in the root folder and
33
* NOT entire folders, check the routes below and add it manually.
34
* If you change route names here, also check the altPaths variable below.
35
*/
36
37
// Set the default page for when no pathname is supplied. Be sure to change the
38
// option for disguiseFiles if the entry point should be hidden.
39
default: config.disguiseFiles ? 'login' : 'index',
40
index: 'index.html',
41
'manifest.json': 'manifest.json',
42
43
/* Users must visit this route if disguiseFiles is enabled. The page loader only
44
* requests the site's contents if it has a local key, which is given by this page.
45
* Be sure to update the following line(s) in src/server.mjs if you change this
46
* variable:
47
* let exemptPages = ['login', .........];
48
* if (pages.default === 'login') exemptPages.push('');
49
*/
50
login: 'pages/misc/deobf/entry-point.html',
51
52
// This route for the error page is also used to define text404 down below.
53
'test-404': 'error.html',
54
/* Main */
55
documentation: 'docs.html',
56
questions: 'faq.html',
57
s: 'pages/frame.html',
58
browsing: 'pages/surf.html',
59
credits: 'pages/nav/credits.html',
60
terms: 'pages/nav/terms.html',
61
/* Games */
62
games: 'pages/nav/directory.html',
63
'web-games': 'pages/nav/games5.html',
64
emulators: 'pages/nav/emulators.html',
65
'flash-games': 'pages/nav/flash.html',
66
'retro-games': 'pages/nav/emulibrary.html',
67
/* Proxies */
68
ultraviolet: 'pages/proxnav/ultraviolet.html',
69
scramjet: 'pages/proxnav/scramjet.html',
70
uverror: 'pages/proxnav/ultraviolet-error.html',
71
sjerror: 'pages/proxnav/scramjet-error.html',
72
rammerhead: 'pages/proxnav/rammerhead.html',
73
/* Proxy Presets */
74
youtube: 'pages/proxnav/preset/youtube.html',
75
apps: 'pages/proxnav/preset/applications.html',
76
/* Misc */
77
flash: 'archive/gfiles/flash/index.html',
78
webretro: 'archive/gfiles/rarch/index.html',
79
'vibe-os': 'archive/vibeOS/index.html',
80
'robots.txt': 'robots.txt',
81
'sitemap.xml': 'sitemap.xml',
82
'browserconfig.xml': 'browserconfig.xml',
83
};
84
85
let externalPages = {
86
github: {
87
default: 'https://github.com/QuiteAFancyEmerald/Holy-Unblocker',
88
aos: 'https://github.com/michalsnik/aos',
89
'bare-module': 'https://github.com/motortruck1221/bare-as-module3',
90
'bare-mux': 'https://github.com/MercuryWorkshop/bare-mux',
91
epoxy: 'https://github.com/MercuryWorkshop/epoxy-tls',
92
fastify: 'https://github.com/fastify/fastify',
93
'font-awesome': 'https://github.com/FortAwesome/Font-Awesome',
94
'libcurl-js': 'https://github.com/ading2210/libcurl.js',
95
'nord-theme': 'https://github.com/nordtheme',
96
scramjet: 'https://github.com/MercuryWorkshop/scramjet',
97
ultraviolet: 'https://github.com/titaniumnetwork-dev/Ultraviolet',
98
wisp: 'https://github.com/MercuryWorkshop/wisp-protocol',
99
},
100
codespaces: 'https://github.com/codespaces',
101
'tor-project': 'https://tb-manual.torproject.org/installation',
102
'titaniumnetwork-documentation': 'https://docs.titaniumnetwork.org',
103
'patreon': 'https://www.patreon.com/holyunblockerlts',
104
'titaniumnetwork-discord': 'https://discord.gg/CwWpdGkuWY',
105
'truffled': 'https://truffled.lol',
106
'rammerhead-discord': 'https://discord.gg/VNT4E7gN5Y',
107
};
108
109
// Override the route names below when usingSEO is disabled in config.json.
110
let altPaths = {
111
games: 'books',
112
'web-games': 'dictionary',
113
emulators: 'catalogue',
114
'flash-games': 'textbook',
115
'retro-games': 'math',
116
ultraviolet: 'networking',
117
scramjet: 'working',
118
uverror: 'network-error',
119
sjerror: 'worker-error',
120
rammerhead: 'physics',
121
youtube: 'wiki',
122
apps: 'software',
123
flash: 'whiteboard',
124
webretro: 'notebook',
125
'vibe-os': 'pencil',
126
github: {
127
'bare-module': 'module',
128
'bare-mux': 'bm',
129
epoxy: 'ep',
130
fastify: 'fs',
131
'libcurl-js': 'ljs',
132
scramjet: 'wr',
133
ultraviolet: 'nt',
134
wisp: 'router',
135
},
136
'titaniumnetwork-documentation': 'docs',
137
codespaces: 'codesp',
138
'tor-project': 'tr',
139
'titaniumnetwork-discord': 'social',
140
'truffled': 'educational',
141
'rammerhead-discord': 'rdis',
142
/* Raw File Names */
143
files: {
144
'scramjet.all.js': 'working.all.js',
145
'scramjet.sw.js': 'working.sw.js',
146
'scramjet.sw-blacklist.js': 'working.sw-blacklist.js',
147
'scramjet.sync.js': 'working.sync.js',
148
'scramjet.wasm.wasm': 'working.wasm.wasm',
149
'uv.handler.js': 'networking.handler.js',
150
'uv.client.js': 'networking.client.js',
151
'uv.bundle.js': 'networking.bundle.js',
152
'uv.config.js': 'networking.config.js',
153
'uv.sw.js': 'networking.sw.js',
154
'uv.webp': 'nt.webp',
155
'scramjet.webp': 'wr.webp',
156
'rammerhead.webp': 'physics.webp',
157
'fastify.webp': 'fs.webp',
158
'nordtheme.webp': 'nord.webp',
159
'nodejs.webp': 'node.webp',
160
'fontawesome.webp': 'fa.webp',
161
'webretro.webp': 'notebook.webp',
162
'ruffle.webp': 'rs.webp',
163
},
164
/* Prefixes */
165
prefixes: {
166
roms: 'ms',
167
uv: 'network',
168
scram: 'worker',
169
chii: 'ani',
170
epoxy: 'epoch',
171
libcurl: 'unix',
172
bareasmodule: 'utc',
173
baremux: 'gmt',
174
wisp: 'cron',
175
},
176
};
177
178
const useAltPaths = (altPaths, targetPaths, ancestor, tempKey = '') => {
179
if ('object' === typeof altPaths) {
180
for (const [key, value] of Object.entries(altPaths)) {
181
if (key in targetPaths) {
182
const isEndPoint = 'object' !== typeof value;
183
delete altPaths[
184
useAltPaths(
185
value,
186
isEndPoint ? targetPaths : targetPaths[key],
187
altPaths,
188
key
189
)
190
];
191
if (isEndPoint) delete targetPaths[key];
192
}
193
}
194
if ('object' === typeof ancestor) delete ancestor[tempKey];
195
} else {
196
targetPaths[altPaths] = targetPaths[tempKey];
197
return tempKey;
198
}
199
return altPaths;
200
};
201
202
const getAltPrefix = (prefix, serverPathname = '/') =>
203
serverPathname +
204
((!config.usingSEO && altPaths.prefixes[prefix]) || prefix) +
205
'/',
206
getPathEntries = (pathObject, prefix = '') => {
207
if (prefix) prefix += '/';
208
let inserts = [];
209
for (let [key, value] of Object.entries(pathObject)) {
210
if ('object' === typeof value)
211
inserts = inserts.concat(getPathEntries(value, key));
212
else
213
inserts.push([
214
prefix + key,
215
prefix.replace(/^(?:prefixes|files)\//, '') +
216
(config.usingSEO ? key : value),
217
]);
218
}
219
return inserts;
220
},
221
normalizePaths = (pathObject) =>
222
Object.fromEntries(getPathEntries(pathObject));
223
224
const flatAltPaths = Object.freeze(normalizePaths(altPaths));
225
226
const insert = JSON.parse(
227
readFileSync(new URL('./data.json', import.meta.url))
228
),
229
text404 = readFileSync(
230
new URL('../views/' + pages['test-404'], import.meta.url),
231
'utf8'
232
),
233
uvError = readFileSync(
234
new URL('../views/' + pages['uverror'], import.meta.url),
235
'utf8'
236
),
237
sjError = readFileSync(
238
new URL('../views/' + pages['sjerror'], import.meta.url),
239
'utf8'
240
);
241
242
if (!config.usingSEO) {
243
useAltPaths(altPaths, pages);
244
useAltPaths(altPaths, externalPages);
245
delete pages['robots.txt'];
246
delete pages['sitemap.xml'];
247
}
248
249
const cookingInserts = insert.content,
250
vegetables = insert.keywords,
251
charRandom = insert.chars,
252
delimiter = insert.delimiter,
253
textMasks = insert.textMasks,
254
splashRandom = insert.splash,
255
versionValue = insert.version,
256
cacheBustList = {
257
'styles.css': 'styles-1755147161.css',
258
'common.js': 'common-1735118314.js',
259
};
260
261
export {
262
config,
263
serverUrl,
264
pages,
265
externalPages,
266
flatAltPaths,
267
getAltPrefix,
268
text404,
269
uvError,
270
sjError,
271
cookingInserts,
272
vegetables,
273
charRandom,
274
delimiter,
275
textMasks,
276
splashRandom,
277
versionValue,
278
cacheBustList,
279
};
280
281