forked from spacesprotocol/explorer
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (34 loc) · 1.15 KB
/
server.js
File metadata and controls
42 lines (34 loc) · 1.15 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
import { handler } from './handler.js';
import express from 'express';
import https from 'https';
import fs from 'fs';
import dotenv from 'dotenv';
dotenv.config();
const app = express();
const port = process.env.PORT || 3000; // Add this line
// add a route that lives separately from the SvelteKit app
app.get('/healthcheck', (req, res) => {
res.end('ok');
});
app.use((req, res, next) => {
if (process.env.DOMAIN && req.headers['host'] != process.env.DOMAIN)
return res.status(403).end();
next();
});
// let SvelteKit handle everything else, including serving prerendered pages and static assets
app.use(handler);
const { SSL_KEY_PATH, SSL_CERT_PATH } = process.env;
if (SSL_CERT_PATH && SSL_KEY_PATH) {
const sslOptions = {
key: fs.readFileSync(process.env.SSL_KEY_PATH), // Path to server.key
cert: fs.readFileSync(process.env.SSL_CERT_PATH) // Path to server.cert
};
https.createServer(sslOptions, app)
.listen(443, () => {
console.log('HTTPS server running on port 443');
});
} else {
app.listen(port, () => {
console.log('HTTP server running on port 3000');
});
}