forked from IamSebastianDev/krankenhausampelbayern.de
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.mjs
43 lines (32 loc) · 1015 Bytes
/
main.mjs
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
/** @format */
// Import dependencies
import './config/dotenv.config.mjs';
import path from 'path';
import Express from 'express';
// Setup the Express app.
const App = Express();
const PORT = process.env.PORT || 31415;
/**
* Create a automatic https redirect if the app is running production mode.
*/
if (process.env.production) {
App.enable('trust proxy');
App.use((req, res, next) =>
req.secure
? next()
: res.redirect('https://' + req.headers.host + req.url)
);
}
import { handleApiRequest, handleAdaptedRequest } from './api/index.mjs';
App.get('/api', handleApiRequest);
App.get('/api/data', handleAdaptedRequest);
App.use(Express.static(path.resolve(process.cwd(), './dashboard/build')));
App.listen(PORT);
/**
* If the app is not runnin in production mode, import the presentDetails method
* and run it to log the details of the package to the console.
*/
if (!process.env.production) {
const { presentDetails } = await import('dev-server-details');
presentDetails({ PORT });
}