Skip to content

Commit

Permalink
Merge pull request #99 from gamelaster/express-middleware
Browse files Browse the repository at this point in the history
Express as middleware
  • Loading branch information
atinux authored May 30, 2018
2 parents d0cf3b6 + 49cbe77 commit adf5f5f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 63 deletions.
6 changes: 1 addition & 5 deletions template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,4 @@ $ npm run dev
$ npm start
```

For detailed explanation on how things work, checkout the [Nuxt.js docs](https://github.com/nuxt/nuxt.js).

## Backpack

We use [backpack](https://github.com/palmerhq/backpack) to watch and build the application, so you can use the latest ES6 features (module syntax, async/await, etc.).
For detailed explanation on how things work, checkout the [Nuxt.js docs](https://github.com/nuxt/nuxt.js).
16 changes: 16 additions & 0 deletions template/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const express = require('express')

// Create express instnace
const app = express()

// Require API routes
const users = require('./routes/users')

// Import API Routes
app.use(users)

// Export the server middleware
module.exports = {
path: '/api',
handler: app
}
6 changes: 3 additions & 3 deletions template/server/api/users.js → template/api/routes/users.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Router } from 'express'
const { Router } = require('express')

const router = Router()

// Mock Users
const users = [
{ name: 'Alexandre' },
{ name: 'Pooya' },
{ name: 'Sébastien' },
{ name: 'Sébastien' }
]

/* GET users listing. */
Expand All @@ -24,4 +24,4 @@ router.get('/users/:id', function (req, res, next) {
}
})

export default router
module.exports = router
6 changes: 0 additions & 6 deletions template/backpack.config.js

This file was deleted.

6 changes: 5 additions & 1 deletion template/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@ module.exports = {
})
}
}
}
},
serverMiddleware: [
// API middleware
'~/api/index.js'
]
}
9 changes: 4 additions & 5 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
"author": "{{ author }}",
"private": true,
"scripts": {
"dev": "backpack dev",
"build": "nuxt build && backpack build",
"start": "cross-env NODE_ENV=production node build/main.js",
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt build && nuxt start",
"precommit": "npm run lint",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore ."
},
"dependencies": {
"axios": "^0.16.2",
"cross-env": "^5.0.1",
"express": "^4.15.3",
"nuxt": "^1.0.0-rc3",
"nuxt": "latest",
"source-map-support": "^0.4.15"
},
"devDependencies": {
"babel-eslint": "^7.2.3",
"backpack-core": "^0.4.1",
"eslint": "^4.3.0",
"eslint-config-standard": "^10.2.1",
"eslint-loader": "^1.9.0",
Expand Down
10 changes: 0 additions & 10 deletions template/server/api/index.js

This file was deleted.

33 changes: 0 additions & 33 deletions template/server/index.js

This file was deleted.

0 comments on commit adf5f5f

Please sign in to comment.