Skip to content

Commit 5364016

Browse files
➕Dependency: Expressjs in anticipation for a need to have a backend
1 parent bb6c3e1 commit 5364016

File tree

4 files changed

+99
-16
lines changed

4 files changed

+99
-16
lines changed

nuxt.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default {
1+
module.exports = {
22
mode: 'universal',
33
/*
44
** Headers of the page
@@ -61,6 +61,6 @@ export default {
6161
/*
6262
** You can extend webpack config here
6363
*/
64-
extend(config, ctx) {}
64+
extend(config, ctx) { }
6565
}
6666
}

package-lock.json

Lines changed: 52 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
"author": "Opensource 254",
66
"private": true,
77
"scripts": {
8-
"dev": "nuxt",
8+
"dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server",
99
"build": "nuxt build",
10-
"start": "nuxt start",
10+
"start": "cross-env NODE_ENV=production node server/index.js",
1111
"generate": "nuxt generate",
1212
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
13-
"test": "jest",
14-
"deploy": "push-dir --dir=dist --branch=master --cleanup"
13+
"test": "jest"
1514
},
1615
"dependencies": {
1716
"nuxt": "^2.0.0",
@@ -28,13 +27,13 @@
2827
"@vue/test-utils": "^1.0.0-beta.27",
2928
"babel-eslint": "^10.0.1",
3029
"babel-jest": "^24.1.0",
30+
"cross-env": "^7.0.2",
3131
"eslint": "^6.1.0",
3232
"eslint-config-prettier": "^6.10.0",
3333
"eslint-plugin-nuxt": ">=0.4.2",
3434
"eslint-plugin-prettier": "^3.1.2",
3535
"jest": "^24.1.0",
3636
"prettier": "^1.19.1",
37-
"push-dir": "^0.4.1",
3837
"stylelint": "^10.1.0",
3938
"vue-jest": "^4.0.0-0"
4039
},

server/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const express = require('express')
2+
const consola = require('consola')
3+
const { Nuxt, Builder } = require('nuxt')
4+
const app = express()
5+
const config = require('../nuxt.config.js')
6+
//const apiRoutes = require('./routes/api')
7+
8+
// Import and Set Nuxt.js options
9+
config.dev = process.env.NODE_ENV !== 'production'
10+
11+
/**
12+
*=============================================================
13+
* API ROUTES called before NUXT
14+
* ============================================================
15+
*/
16+
//app.use('/api', apiRoutes)
17+
18+
async function start() {
19+
// Init Nuxt.js
20+
const nuxt = new Nuxt(config)
21+
22+
const { host, port } = nuxt.options.server
23+
24+
await nuxt.ready()
25+
// Build only in dev mode
26+
if (config.dev) {
27+
const builder = new Builder(nuxt)
28+
await builder.build()
29+
}
30+
31+
// Give nuxt middleware to express
32+
app.use(nuxt.render)
33+
34+
// Listen the server
35+
app.listen(port, host)
36+
consola.ready({
37+
message: `Server listening on http://${host}:${port}`,
38+
badge: true
39+
})
40+
}
41+
start()

0 commit comments

Comments
 (0)