-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
57 lines (53 loc) · 1.74 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
47
48
49
50
51
52
53
54
55
56
57
const express = require('express')
const path = require('path')
const http = require('http')
const https = require('https')
const fs = require('fs')
const app = express()
// serve static assets normally
app.use(
express.static(path.resolve(__dirname, '/dist'))
)
// viewed at https://localhost:8080
app.get('/bundle.js', (req, res) => {
res.sendFile(path.resolve(__dirname, './dist/bundle.js'))
})
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, './dist/index.html'))
})
// Server setup
if (process.env.NODE_ENV === 'production') {
const options = {
ca: fs.readFileSync('./creds/example_SSL_cert.ca-bundle'),
key: fs.readFileSync('./creds/example_SSL_cert.key'),
cert: fs.readFileSync('./creds/example_SSL_cert.crt'),
requestCert: false,
rejectUnauthorized: false
}
// create a server with the native node https library
const server = https.createServer(options, app)
const port = process.env.PORT || 5000
// listen to the server on port
server.listen(port, () => {
console.log('Server listening on https: ', port)
})
} else {
// const options = {
// key: fs.readFileSync('./creds/example_SSL_cert.key'),
// cert: fs.readFileSync('./creds/example_SSL_cert.crt'),
// requestCert: false,
// rejectUnauthorized: false
// }
// // create a server with the native node https library
// const server = https.createServer(options, app)
// const port = process.env.PORT || 4001
// // listen to the server on port
// server.listen(port, () => {
// console.log('Server listening on https: ', port)
// })
const port = process.env.PORT || 5001
const server = http.createServer(app)
server.listen(port, () => {
console.log('Server listening on http: ', port)
})
}