-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
85 lines (67 loc) · 1.82 KB
/
Copy pathserver.js
File metadata and controls
85 lines (67 loc) · 1.82 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { Nuxt, Builder } = require('nuxt')
const express = require('express')
const http = require('http')
const https = require('https')
const fs = require('fs')
const forceSsl = require('express-force-ssl')
const isProd = (process.env.NODE_ENV === 'production')
const port = process.env.PORT || 3001
const api = require("./server-middleware/api.ts");
const app = module.exports = express()
// We instantiate nuxt.js with the options
const confignuxt = require('./nuxt.config.js')
config.dev = !isProd
async function start() {
const nuxt = new Nuxt(confignuxt)
const { host, port } = nuxt.options.server
const options = {
key: fs.readFileSync('sslcert/localhost.key'),
cert: fs.readFileSync('sslcert/localhost.crt')
};
// Render every route with Nuxt.js
// Build only in dev mode with hot-reloading
/*
if (config.dev) {
new Builder(nuxt).build()
.then(listen)
.catch((error) => {
console.error(error)
//process.exit(1)
})
}
else {
listen()
}
*/
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
} else {
await nuxt.ready()
}
//Give nuxt middleware to express
app.use(nuxt.render.use(forceSsl))
app.use(api)
https
.createServer(options, app)
.listen(port)
console.log('The server is listening on `localhost:' + port + '`.')
}
start()
/*
function listen() {
const options = {
key: fs.readFileSync('sslcert/localhost.key'),
cert: fs.readFileSync('sslcert/localhost.crt')
};
https
.createServer(options, nuxt.render.use(forceSsl))
.listen(3001)
console.log('https server listening on `localhost:' + '3001' + '`.')
http
.createServer(options, nuxt.render.use(forceSsl))
.listen(3000)
console.log('http server listening on `localhost:' + '3000' + '`.')
}
*/