-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (42 loc) · 1.53 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
const express = require('express');
const https = require('https');
const fs = require('fs');
const next = require('next');
const dotenv = require("dotenv");
const morgan = require("morgan");
const bodyParser = require('body-parser');
const cors = require("cors");
const path = require('path');
const connectToMongodb = require('./src/db/mongodb');
dotenv.config({ path: "./.env" });
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
console.log('started')
app.prepare().then(() => {
const server = express();
server.use(morgan('dev'))
server.use(express.json());
server.use(cors());
server.use(bodyParser.json());
server.use(express.static(path.join(__dirname, 'public')))
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
console.error('before connecting...')
connectToMongodb();
console.error('after connecting...')
console.log('after connecting...')
server.all('*', (req, res) => {
return handle(req, res);
// res.send("<h1>This site is temporarily down.</h1> <p>The website developer is waiting response from <b>Syed Mosawi.</b></p><p> Please contact developer.</p> Skype or telegram is available.<i> [email protected]</i>");
});
// server.listen(process.env.PORT, (err) => {
// if (err) throw err;
// console.log('> Ready on http://localhost:' + process.env.PORT);
// });
https.createServer(options, server).listen(443, () => {
console.log('Server running on https://localhost');
});
});