-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (35 loc) · 1.09 KB
/
server.js
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
import { handler } from './build/handler.js';
import express from 'express';
import dotenv from 'dotenv';
import cors from 'cors';
dotenv.config();
console.log({ok: process.env.DATABASE_URL});
const app = express();
import os from 'os';
const getIPAddress = () => {
const interfaces = os.networkInterfaces();
for (const iface in interfaces) {
for (const alias of interfaces[iface]) {
if (alias.family === 'IPv4' && !alias.internal) {
return alias.address;
}
}
}
return '0.0.0.0';
};
const corsOptions = {
origin: '*', // Adjust this as needed for your environment
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', // Specify allowed methods
allowedHeaders: '*', // Allow any header
credentials: true, // Set to true if your frontend needs to pass credentials (cookies, HTTP authentication)
optionsSuccessStatus: 204 // Some legacy browsers choke on 204
};
app.use(cors(corsOptions));
app.get('/healthcheck', (req, res) => {
res.end('ok');
});
app.use(handler);
app.listen(3000, '0.0.0.0', () => {
console.log('my own ip',getIPAddress())
console.log('listening on port 3000');
});