This repository was archived by the owner on Apr 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (55 loc) · 2.04 KB
/
Copy pathindex.js
File metadata and controls
70 lines (55 loc) · 2.04 KB
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
64
65
66
67
68
69
70
import express from "express";
import Handlebars from 'handlebars';
import { engine } from 'express-handlebars';
import config from './config.js';
import coreServer from './core/server.js';
import dotenv from 'dotenv';
import http from 'http';
import path from 'path';
import { fileURLToPath } from 'url';
dotenv.config();
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Import core functions
import core from './core/core.js';
// Import middlewares and helpers
import cookieParser from 'cookie-parser'; // Parse cookies
import handlebarsHelpers from './app/helpers/handlebarsHelpers.js'; // Register the handlebars helpers
import moduleStatics from './app/middlewares/moduleStatics.js';
import registerPartials from './app/middlewares/registerPartials.js';
// Import routes
import authRoutes from "./app/routes/authRoutes.js";
import moduleRoutes from "./app/routes/moduleRoutes.js";
import coreRoutes from "./app/routes/coreRoutes.js";
// Create an Express application
const app = express();
// Run the core initialization function
core.init();
// Register partials
registerPartials();
// Set up Handlebars
app.engine("hbs", engine({ defaultLayout: false}));
app.set('view engine', 'hbs');
app.set("views", config.viewsPath);
// Register Handlebars helpers
Object.keys(handlebarsHelpers).forEach((helperName) => {
Handlebars.registerHelper(helperName, handlebarsHelpers[helperName]);
});
// Middleware configuration
app.use(express.urlencoded({ extended: true })); // Parse form data
app.use(express.json()); // Parse JSON bodies
app.use(cookieParser()); // Access cookies
app.use(express.static(config.publicPath)); // Serve static files
// setup module static files
moduleStatics(path.join(__dirname, 'modules'))(app);
// Route configuration
app.use("/", authRoutes);
app.use("/mod", moduleRoutes);
app.use("/", coreRoutes);
// Create HTTP server
const server = http.createServer(app);
// Setup WebSocket
coreServer.realtime.init(server);
// Start server
server.listen(config.port, () => {
console.log(`Server is running on port ${config.port}`);
});