Created
October 15, 2017 17:08
-
-
Save nirvanagit/037d1c5715cf0bf5c434008e680e917f to your computer and use it in GitHub Desktop.
server.js file for nuxt.js server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//import express from 'express' | |
import https from 'https' | |
import { Nuxt, Builder } from 'nuxt' | |
import bodyParser from 'body-parser' | |
import fs from 'fs' | |
import api from './api' | |
const key = fs.readFileSync('certificates/private.key'); | |
const cert = fs.readFileSync( 'certificates/mydomain.crt' ); | |
const ca = fs.readFileSync( 'certificates/mydomain.crt' ); | |
const options = { | |
key: key, | |
cert: cert, | |
ca: ca | |
}; | |
//const app = express() | |
//app.use(bodyParser.json()); // for parsing application/json | |
//app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded | |
const host = process.env.HOST || '127.0.0.1' | |
const port = process.env.PORT || 3000 | |
//app.set('port', port) | |
// Import API Routes | |
//app.use('/api', api) | |
// Import and Set Nuxt.js options | |
let config = require('../nuxt.config.js') | |
config.dev = !(process.env.NODE_ENV === 'production') | |
// Init Nuxt.js | |
const nuxt = new Nuxt(config) | |
// Build only in dev mode | |
if (config.dev) { | |
const builder = new Builder(nuxt) | |
builder.build() | |
} | |
// Give nuxt middleware to express | |
//app.use(nuxt.render) | |
// Listen the server | |
// app.listen(port, host) | |
https.createServer(options, nuxt.render).listen(3000, host) | |
console.log('Server listening on ' + host + ':' + port) // eslint-disable-line no-console |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment