Skip to content

Instantly share code, notes, and snippets.

@nirvanagit
Created October 15, 2017 17:08
Show Gist options
  • Save nirvanagit/037d1c5715cf0bf5c434008e680e917f to your computer and use it in GitHub Desktop.
Save nirvanagit/037d1c5715cf0bf5c434008e680e917f to your computer and use it in GitHub Desktop.
server.js file for nuxt.js server
//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