-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathserver.js
More file actions
66 lines (63 loc) · 1.73 KB
/
server.js
File metadata and controls
66 lines (63 loc) · 1.73 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
import fs from 'fs';
import path from 'path';
import https from 'https';
import { config, logger } from 'copilot-instructions-mcp/core';
import app from './src/express_app.js';
function listenHTTP() {
app.listen(config.server.port, (error) => {
if (error) {
logger.error('Error starting server', {
source: 'server.listenHTTP',
details: {
port: config.server.port,
hostname: config.server.hostname,
},
error: {
message: error.message || 'Unknown error',
stack: error.stack || 'No stack trace available',
},
});
} else {
logger.info(`Server listening on port ${config.server.port}`, {
source: 'server.listenHTTP',
details: {
port: config.server.port,
hostname: config.server.hostname,
},
});
}
});
}
function listenHTTPS() {
https.createServer({
pfx: fs.readFileSync(path.resolve(config.server['ssl.pfx'])),
passphrase: config.server['ssl.pfx.passphrase'],
}, app).listen(config.server.port, (error) => {
if (error) {
logger.error('Error starting server', {
source: 'server.listenHTTPS',
details: {
port: config.server.port,
hostname: config.server.hostname,
},
error: {
message: error.message || 'Unknown error',
stack: error.stack || 'No stack trace available',
},
});
} else {
logger.info(`Server listening on port ${config.server.port}`, {
source: 'server.listenHTTPS',
details: {
port: config.server.port,
hostname: config.server.hostname,
},
});
}
});
}
if (config.server.ssl) {
listenHTTPS();
} else {
listenHTTP();
}