@fleitor/fl-back
v1.1.5
Published
### Project structuring ``` /bin - www /config - database.js /resources /routes - app.js ```
Downloads
21
Readme
Fleitor Back
Project structuring
/bin
- www
/config
- database.js
/resources
/routes
- app.js
/bin/www
is responsible for creating HTTP server and running the app./config/database.js
stands for configuring database./resources
Folder for configuring all the endpoints/routes
Folder for writing custom routesapp.js
The bootstrapper
Defining resources
- app.js
const definedResources = require('./resources')
definedResources.forEach(resource => {
if (resource.name === 'auth') {
app.use(resource.route, flBack.authRouter({ resource }))
} else {
app.use(resource.route, flBack.abstractRouter({ resource }))
}
})
Creation of regular endpoint
Authentication
The table/collection which is stands for storing users, required to have this fields.
email Varchar()
password Varchar(60)
token Varchar(60)
tokenExpireDate DATETIME
Create resource with the specified keys, where the value of usersResource
is the object of Users resource.
// auth.js
const usersResource = require('./users')
module.exports = {
name: 'auth',
route: '/auth',
requireAuthorization: false,
usersResource,
}
The authentication resource should be defined in the app.js to be used as flBack.authRouter
instead of flBack.abstractRouter
definedResources.forEach(resource => {
if (resource.name === 'auth') {
app.use(resource.route, flBack.authRouter({ resource }))
} else {
app.use(resource.route, flBack.abstractRouter({ resource }))
}
})
After that it will automatically setup endpoints for registering and signing in.
So if the route defined as /auth
in the authentication resource, then the endpoints should be:
POST /auth/register
POST /auth/login