Spaces:
Running
Running
| // | |
| // SPDX-FileCopyrightText: Hadad <[email protected]> | |
| // SPDX-License-Identifier: Apache-2.0 | |
| // | |
| import express from 'express'; | |
| import { createServer } from 'http'; | |
| import { WebSocketServer } from 'ws'; | |
| import { fileURLToPath } from 'url'; | |
| import path from 'path'; | |
| import config from './config.js'; | |
| import imageRoutes from | |
| './src/routes/imageRoutes.js'; | |
| import { initCleanup } from | |
| './src/services/storageManager.js'; | |
| import { setupViewEngine } from | |
| './src/middleware/viewEngine.js'; | |
| import { setupWebSocket } from | |
| './src/services/websocketManager.js'; | |
| const __filename = fileURLToPath(import.meta.url); | |
| const __dirname = path.dirname(__filename); | |
| const app = express(); | |
| const mapping = { | |
| "/__public__/assets": "assets", | |
| "/__public__/data/models.js": "model.js", | |
| "/__public__/data/resolution.js": "resolution.js", | |
| "/__public__/data/examples.js": "example.js" | |
| }; | |
| const server = createServer(app); | |
| const wss = new WebSocketServer({ server }); | |
| setupViewEngine(app, __dirname); | |
| setupWebSocket(wss); | |
| app.use(express.urlencoded({ | |
| extended: true, | |
| limit: config.limits.bodySize | |
| })); | |
| app.use(express.json({ | |
| limit: config.limits.bodySize | |
| })); | |
| for (const [route, target] | |
| of Object.entries(mapping) | |
| ) { | |
| app.use( | |
| route, | |
| express.static( | |
| path.resolve(target) | |
| ) | |
| ); | |
| } | |
| app.use('/', imageRoutes); | |
| initCleanup(); | |
| server.listen( | |
| config.server.port, | |
| config.server.host | |
| ); |