What is nuxt-server?
It is HTTP and HTTPS server for nuxt.
Setup
nuxt.config.js
cert: {
mode: 'http',
setup: {
http: {
port: 8080
},
https: {
port: 8443,
path: {
key: './path/to/file/example.key',
cert: './path/to/file/example.crt',
ca: ['./path/to/file/example.txt']
},
handshakeTimeout: 120,
requestCert: false,
rejectUnauthorized: true
}
}
}
OU
export CERT_MODE=http
export HTTP_PORT=8080
export HTTPS_PORT=8443
export PATH_KEY=./path/to/file/example.key
export PATH_CERT=./path/to/file/example.crt
export PATH_CA=./path/to/file/example.txt
export HANDSHAKE_TIMEOUT=120
export REQUEST_CERT=false
export REJECT_UNAUTHORIZED=true
server.js
const {Nuxt, Builder} = require('nuxt');
const NuxtServer = require('nuxt-server');
const config = require('../nuxt.config.js');
const server = new NuxtServer(Nuxt, Builder, config);
server.run(function(err, ports) {
if (err) console.error(err);
console.log(ports);
});
const psRun = server.run();
psRun.then(function(ports) {
console.log(ports);
});
psRun.catch(function(err) {
console.error(err);
});
package.json
"scripts": {
"start": "node server.js"
},