2019-06-07 17:02:33 +02:00
|
|
|
#!/bin/env node
|
|
|
|
const path = require('path')
|
2019-04-03 00:25:12 +02:00
|
|
|
const express = require('express')
|
|
|
|
const consola = require('consola')
|
2019-04-23 15:45:52 +02:00
|
|
|
const morgan = require('morgan')
|
2019-06-06 23:54:32 +02:00
|
|
|
const { Nuxt, Builder } = require('nuxt')
|
2019-06-07 17:02:33 +02:00
|
|
|
const firstRun = require('./firstrun')
|
2019-04-03 00:25:12 +02:00
|
|
|
// Import and Set Nuxt.js options
|
|
|
|
const config = require('../nuxt.config.js')
|
|
|
|
|
2019-06-07 17:02:33 +02:00
|
|
|
const app = express()
|
2019-04-03 00:25:12 +02:00
|
|
|
async function start() {
|
|
|
|
// Init Nuxt.js
|
|
|
|
const nuxt = new Nuxt(config)
|
|
|
|
|
|
|
|
const { host, port } = nuxt.options.server
|
|
|
|
|
|
|
|
// 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
|
2019-04-23 15:45:52 +02:00
|
|
|
app.use(morgan('dev'))
|
2019-04-29 00:27:29 +02:00
|
|
|
app.use('/media/', express.static(path.join(__dirname, '..', 'uploads')))
|
2019-04-03 00:25:12 +02:00
|
|
|
app.use(nuxt.render)
|
|
|
|
|
|
|
|
// Listen the server
|
|
|
|
app.listen(port, host)
|
|
|
|
consola.ready({
|
|
|
|
message: `Server listening on http://${host}:${port}`,
|
|
|
|
badge: true
|
|
|
|
})
|
|
|
|
}
|
2019-06-06 23:54:32 +02:00
|
|
|
|
2019-06-07 17:02:33 +02:00
|
|
|
firstRun.then(start)
|