diff options
author | bobzel <zzzman@gmail.com> | 2025-08-14 11:00:14 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2025-08-14 11:00:14 -0400 |
commit | 467f1c2543626a50d48c84669cd408571260f147 (patch) | |
tree | 2cb3599c4ca95fe2b975deb8dc72283151e1c585 /src/server/server_Initialization.ts | |
parent | 5b0b7241e68febc2d0556b6c2e8349411b5c12a0 (diff) |
added background removal for images.
Diffstat (limited to 'src/server/server_Initialization.ts')
-rw-r--r-- | src/server/server_Initialization.ts | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/server/server_Initialization.ts b/src/server/server_Initialization.ts index 5deb66caf..7915938b7 100644 --- a/src/server/server_Initialization.ts +++ b/src/server/server_Initialization.ts @@ -1,3 +1,4 @@ +import axios from 'axios'; import * as bodyParser from 'body-parser'; import { blue, yellow } from 'colors'; import * as flash from 'connect-flash'; @@ -6,22 +7,22 @@ import * as express from 'express'; import * as expressFlash from 'express-flash'; import * as session from 'express-session'; import { createServer } from 'https'; +import { JSDOM } from 'jsdom'; import * as passport from 'passport'; import * as webpack from 'webpack'; import * as wdm from 'webpack-dev-middleware'; import * as whm from 'webpack-hot-middleware'; import * as config from '../../webpack.config'; +import * as workerConfig from '../../webpack.worker.config'; import { logPort } from './ActionUtilities'; import RouteManager from './RouteManager'; import RouteSubscriber from './RouteSubscriber'; import { publicDirectory, resolvedPorts } from './SocketData'; +import { setupDynamicToolsAPI } from './api/dynamicTools'; import { SSL } from './apis/google/CredentialsLoader'; import { getForgot, getLogin, getLogout, getReset, getSignup, postForgot, postLogin, postReset, postSignup } from './authentication/AuthenticationManager'; import { Database } from './database'; import { WebSocket } from './websocket'; -import axios from 'axios'; -import { JSDOM } from 'jsdom'; -import { setupDynamicToolsAPI } from './api/dynamicTools'; /* RouteSetter is a wrapper around the server that prevents the server from being exposed. */ @@ -126,13 +127,12 @@ function registerCorsProxy(server: express.Express) { //res.status(400).json({ error: 'Invalid URL format' }); return; } - const isBinary = /\.(gif|png|jpe?g|bmp|webp|ico|pdf|zip|mp3|mp4|wav|ogg)$/i.test(targetUrl as string); const responseType = isBinary ? 'arraybuffer' : 'text'; const response = await axios.get(targetUrl as string, { headers: { 'User-Agent': req.headers['user-agent'] || 'Mozilla/5.0' }, - responseType: responseType + responseType: responseType, }); const baseUrl = new URL(targetUrl as string); @@ -200,8 +200,13 @@ function registerAuthenticationRoutes(server: express.Express) { export default async function InitializeServer(routeSetter: RouteSetter) { const isRelease = determineEnvironment(); const app = buildWithMiddleware(express()); + const workerCompiler = webpack(workerConfig as webpack.Configuration); const compiler = webpack(config as webpack.Configuration); + if (!compiler) throw new Error('Webpack compiler is not defined. Please check your webpack configuration.'); + if (!workerCompiler) throw new Error('Webpack worker compiler is not defined. Please check your webpack worker configuration.'); + // print out contents of virtual output filesystem used in development + // compiler.outputFileSystem?.readdir?.(config.output.path, (err, files) => (err ? console.error('Error reading virtual output path:', err) : console.log('Files in virtual output path:', files))); // Default route app.get('/', (req, res) => { res.redirect(req.user ? '/home' : '/login'); //res.send('This is the default route.'); @@ -209,6 +214,8 @@ export default async function InitializeServer(routeSetter: RouteSetter) { // 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.use(wdm(workerCompiler, { publicPath: workerConfig.output.publicPath })); + app.use(whm(workerCompiler)); 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) // app.use(cors({ origin: (_origin: any, callback: any) => callback(null, true) })); |