File size: 1,423 Bytes
c34c995 4f33245 c34c995 4f33245 c34c995 4f33245 c34c995 4f33245 c34c995 4f33245 c34c995 4f33245 c34c995 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
//
// SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org>
// 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
); |