aboutsummaryrefslogtreecommitdiff
path: root/src/server/server_Initialization.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-09-02 09:26:37 -0400
committerbobzel <zzzman@gmail.com>2024-09-02 09:26:37 -0400
commitcda69e48361fce8d71a4dc66edd9dd976a27f52d (patch)
tree82b9a1a5967ae88a9534f89f7eaed3aeb289652f /src/server/server_Initialization.ts
parentc01828308714874589d1f60c33ca59df4c656c0c (diff)
parenta958577d4c27b276aa37484e3f895e196138b17c (diff)
Merge branch 'master' into alyssa-starter
Diffstat (limited to 'src/server/server_Initialization.ts')
-rw-r--r--src/server/server_Initialization.ts16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/server/server_Initialization.ts b/src/server/server_Initialization.ts
index 9183688c6..0cf9a6e58 100644
--- a/src/server/server_Initialization.ts
+++ b/src/server/server_Initialization.ts
@@ -29,7 +29,6 @@ import { WebSocket } from './websocket';
export type RouteSetter = (server: RouteManager) => void;
// export let disconnect: Function;
-// eslint-disable-next-line import/no-mutable-exports
export let resolvedServerUrl: string;
const week = 7 * 24 * 60 * 60 * 1000;
@@ -114,13 +113,14 @@ function registerEmbeddedBrowseRelativePathHandler(server: express.Express) {
});
}
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
function proxyServe(req: any, requrl: string, response: any) {
- // eslint-disable-next-line global-require
+ // eslint-disable-next-line global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const htmlBodyMemoryStream = new (require('memorystream'))();
let wasinBrFormat = false;
const sendModifiedBody = () => {
const header = response.headers['content-encoding'];
- const refToCors = (match: any, tag: string, sym: string, href: string) => `${tag}=${sym + resolvedServerUrl}/corsProxy/${href + sym}`;
+ const refToCors = (match: string, tag: string, sym: string, href: string) => `${tag}=${sym + resolvedServerUrl}/corsProxy/${href + sym}`;
// const relpathToCors = (match: any, href: string, offset: any, string: any) => `="${resolvedServerUrl + '/corsProxy/' + decodeURIComponent(req.originalUrl.split('/corsProxy/')[1].match(/https?:\/\/[^\/]*/)?.[0] ?? '') + '/' + href}"`;
if (header) {
try {
@@ -138,8 +138,10 @@ function proxyServe(req: any, requrl: string, response: any) {
response.send(header?.includes('gzip') ? zlib.gzipSync(htmlText) : htmlText);
} else {
req.pipe(request(requrl))
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
.on('error', (e: any) => console.log('requrl ', e))
.pipe(response)
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
.on('error', (e: any) => console.log('response pipe error', e));
console.log('EMPTY body:' + req.url);
}
@@ -148,14 +150,17 @@ function proxyServe(req: any, requrl: string, response: any) {
}
} else {
req.pipe(htmlBodyMemoryStream)
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
.on('error', (e: any) => console.log('html body memorystream error', e))
.pipe(response)
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
.on('error', (e: any) => console.log('html body memory stream response error', e));
}
};
const retrieveHTTPBody = () => {
// req.headers.cookie = '';
req.pipe(request(requrl))
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
.on('error', (e: any) => {
console.log(`CORS url error: ${requrl}`, e);
response.send(`<html><body bgcolor="red" link="006666" alink="8B4513" vlink="006666">
@@ -164,6 +169,7 @@ function proxyServe(req: any, requrl: string, response: any) {
<p>${e}</p>
</body></html>`);
})
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
.on('response', (res: any) => {
res.headers;
const headers = Object.keys(res.headers);
@@ -188,6 +194,7 @@ function proxyServe(req: any, requrl: string, response: any) {
})
.on('end', sendModifiedBody)
.pipe(htmlBodyMemoryStream)
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
.on('error', (e: any) => console.log('http body pipe error', e));
};
retrieveHTTPBody();
@@ -238,13 +245,14 @@ function registerAuthenticationRoutes(server: express.Express) {
export default async function InitializeServer(routeSetter: RouteSetter) {
const isRelease = determineEnvironment();
const app = buildWithMiddleware(express());
- const compiler = webpack(config as any);
+ const compiler = webpack(config as webpack.Configuration);
// route table managed by express. routes are tested sequentially against each of these map rules. when a match is found, the handler is called to process the request
app.use(wdm(compiler, { publicPath: config.output.publicPath }));
app.use(whm(compiler));
app.get(/^\/+$/, (req, res) => res.redirect(req.user ? '/home' : '/login')); // target urls that consist of one or more '/'s with nothing in between
app.use(express.static(publicDirectory, { setHeaders: res => res.setHeader('Access-Control-Allow-Origin', '*') })); // all urls that start with dash's public directory: /files/ (e.g., /files/images, /files/audio, etc)
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
app.use(cors({ origin: (_origin: any, callback: any) => callback(null, true) }));
registerAuthenticationRoutes(app); // this adds routes to authenticate a user (login, etc)
registerCorsProxy(app); // this adds a /corsProxy/ route to allow clients to get to urls that would otherwise be blocked by cors policies