Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
QuiteAFancyEmerald
GitHub Repository: QuiteAFancyEmerald/Holy-Unblocker
Path: blob/master/src/routes.mjs
5156 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
'titaniumnetwork-discord': 'https://discord.gg/CwWpdGkuWY',
104
'truffled': 'https://truffled.lol',
105
'rammerhead-discord': 'https://discord.gg/VNT4E7gN5Y',
106
};
107
108
// Override the route names below when usingSEO is disabled in config.json.
109
let altPaths = {
110
games: 'books',
111
'web-games': 'dictionary',
112
emulators: 'catalogue',
113
'flash-games': 'textbook',
114
'retro-games': 'math',
115
ultraviolet: 'networking',
116
scramjet: 'working',
117
uverror: 'network-error',
118
sjerror: 'worker-error',
119
rammerhead: 'physics',
120
youtube: 'wiki',
121
apps: 'software',
122
flash: 'whiteboard',
123
webretro: 'notebook',
124
'vibe-os': 'pencil',
125
github: {
126
'bare-module': 'module',
127
'bare-mux': 'bm',
128
epoxy: 'ep',
129
fastify: 'fs',
130
'libcurl-js': 'ljs',
131
scramjet: 'wr',
132
ultraviolet: 'nt',
133
wisp: 'router',
134
},
135
'titaniumnetwork-documentation': 'docs',
136
codespaces: 'codesp',
137
'tor-project': 'tr',
138
'titaniumnetwork-discord': 'social',
139
'truffled': 'educational',
140
'rammerhead-discord': 'rdis',
141
/* Raw File Names */
142
files: {
143
'scramjet.all.js': 'working.all.js',
144
'scramjet.sw.js': 'working.sw.js',
145
'scramjet.sw-blacklist.js': 'working.sw-blacklist.js',
146
'scramjet.sync.js': 'working.sync.js',
147
'scramjet.wasm.wasm': 'working.wasm.wasm',
148
'uv.handler.js': 'networking.handler.js',
149
'uv.client.js': 'networking.client.js',
150
'uv.bundle.js': 'networking.bundle.js',
151
'uv.config.js': 'networking.config.js',
152
'uv.sw.js': 'networking.sw.js',
153
'uv.webp': 'nt.webp',
154
'scramjet.webp': 'wr.webp',
155
'rammerhead.webp': 'physics.webp',
156
'fastify.webp': 'fs.webp',
157
'nordtheme.webp': 'nord.webp',
158
'nodejs.webp': 'node.webp',
159
'fontawesome.webp': 'fa.webp',
160
'webretro.webp': 'notebook.webp',
161
'ruffle.webp': 'rs.webp',
162
},
163
/* Prefixes */
164
prefixes: {
165
roms: 'ms',
166
uv: 'network',
167
scram: 'worker',
168
chii: 'ani',
169
epoxy: 'epoch',
170
libcurl: 'unix',
171
bareasmodule: 'utc',
172
baremux: 'gmt',
173
wisp: 'cron',
174
},
175
};
176
177
const useAltPaths = (altPaths, targetPaths, ancestor, tempKey = '') => {
178
if ('object' === typeof altPaths) {
179
for (const [key, value] of Object.entries(altPaths)) {
180
if (key in targetPaths) {
181
const isEndPoint = 'object' !== typeof value;
182
delete altPaths[
183
useAltPaths(
184
value,
185
isEndPoint ? targetPaths : targetPaths[key],
186
altPaths,
187
key
188
)
189
];
190
if (isEndPoint) delete targetPaths[key];
191
}
192
}
193
if ('object' === typeof ancestor) delete ancestor[tempKey];
194
} else {
195
targetPaths[altPaths] = targetPaths[tempKey];
196
return tempKey;
197
}
198
return altPaths;
199
};
200
201
const getAltPrefix = (prefix, serverPathname = '/') =>
202
serverPathname +
203
((!config.usingSEO && altPaths.prefixes[prefix]) || prefix) +
204
'/',
205
getPathEntries = (pathObject, prefix = '') => {
206
if (prefix) prefix += '/';
207
let inserts = [];
208
for (let [key, value] of Object.entries(pathObject)) {
209
if ('object' === typeof value)
210
inserts = inserts.concat(getPathEntries(value, key));
211
else
212
inserts.push([
213
prefix + key,
214
prefix.replace(/^(?:prefixes|files)\//, '') +
215
(config.usingSEO ? key : value),
216
]);
217
}
218
return inserts;
219
},
220
normalizePaths = (pathObject) =>
221
Object.fromEntries(getPathEntries(pathObject));
222
223
const flatAltPaths = Object.freeze(normalizePaths(altPaths));
224
225
const insert = JSON.parse(
226
readFileSync(new URL('./data.json', import.meta.url))
227
),
228
text404 = readFileSync(
229
new URL('../views/' + pages['test-404'], import.meta.url),
230
'utf8'
231
),
232
uvError = readFileSync(
233
new URL('../views/' + pages['uverror'], import.meta.url),
234
'utf8'
235
),
236
sjError = readFileSync(
237
new URL('../views/' + pages['sjerror'], import.meta.url),
238
'utf8'
239
);
240
241
if (!config.usingSEO) {
242
useAltPaths(altPaths, pages);
243
useAltPaths(altPaths, externalPages);
244
}
245
246
const cookingInserts = insert.content,
247
vegetables = insert.keywords,
248
charRandom = insert.chars,
249
delimiter = insert.delimiter,
250
textMasks = insert.textMasks,
251
splashRandom = insert.splash,
252
versionValue = insert.version,
253
cacheBustList = {
254
'styles.css': 'styles-1755147161.css',
255
'common.js': 'common-1735118314.js',
256
};
257
258
export {
259
config,
260
serverUrl,
261
pages,
262
externalPages,
263
flatAltPaths,
264
getAltPrefix,
265
text404,
266
uvError,
267
sjError,
268
cookingInserts,
269
vegetables,
270
charRandom,
271
delimiter,
272
textMasks,
273
splashRandom,
274
versionValue,
275
cacheBustList,
276
};
277
278