-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
76 lines (51 loc) · 1.89 KB
/
server.js
File metadata and controls
76 lines (51 loc) · 1.89 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
71
72
73
74
75
76
// ============================================
// server.js for WebShell standalone mode
// ============================================
import express from "express";
import http from "http";
import dotenv from "dotenv";
import { WebShellServer } from "./server/server-webshell.js";
// Load environment variables
dotenv.config();
/**
* Main server application setup and initialisation
*
* Creates Express app, HTTP server, and WebShell server instance,
* then starts the complete WebShell service.
*/
async function startServer() {
try {
console.log('[SERVER] Starting WebShell application...');
// Create Express application and HTTP server
const app = express();
const server = http.createServer(app);
// Configure basic Express middlewares
setupBasicMiddlewares(app);
// Create and initialise WebShell server
const webshell = new WebShellServer(app, server, {
shouldStart: true
});
await webshell.initialise();
await webshell.start();
console.log('[SERVER] WebShell application started successfully');
} catch (error) {
console.error('[SERVER] Failed to start WebShell application:', error.message);
process.exit(1);
}
}
/**
* Configures basic Express middlewares for JSON parsing and static files
*
* @param {Object} app - Express application instance
*/
function setupBasicMiddlewares(app) {
console.log('[SERVER] Configuring basic middlewares...');
// JSON parsing with size limits
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ extended: true, limit: '50mb' }));
// Serve static files from dist directory
app.use(express.static('dist'));
console.log('[SERVER] Basic middlewares configured');
}
// Start the server
startServer();