bender-router-builder
v1.0.3
Published
bender-router-builder
Downloads
1
Readme
bender-router-builder
Description
Simple express router builder. Use it if you don`t want to think about the routing of your server application.
Features
- GET
- POST
- Upload file (in development)
Example
project
├── features
| ├── index.js
| └── users.js
├── ...
├── server.js
└── front.vue
index.js
const buider = require('bender-router-builder')
const path = `${__dirname}`
module.exports = buider({ path: path })
path - path to your api
users.js
function getUsers (id) {
const users = [
{ id: 1, name: 'Tom' },
{ id: 2, name: 'Jack' },
{ id: 3, name: 'Max' },
]
return users.find(u => u.id === id)
}
module.exports = {
getUsers
}
or
users.js
function getUsers (id) {
const users = [
{ id: 1, name: 'Tom' },
{ id: 2, name: 'Jack' },
{ id: 3, name: 'Max' },
]
return users.find(u => u.id === id)
}
module.exports = getUsers
server.js
const express = require('express')
const app = express()
...
app.use('/', require('../features'))
app.use(express.static(`${__dirname}/../features`))
...
front.vue
<template>
...
</template>
<script>
import axios from 'axios'
export default {
async mounted () {
const users = await axios({
method: 'get',
url: '/users.getUsers',
params: id,
})
.then(r => r.data)
}
}
</script>