1.1.5 • Published 2 years ago
@fleitor/fl-back v1.1.5
Fleitor Back
Project structuring
/bin
    - www
/config
    - database.js
/resources
/routes
- app.js- /bin/wwwis responsible for creating HTTP server and running the app.
- /config/database.jsstands for configuring database.
- /resourcesFolder for configuring all the endpoints
- /routesFolder for writing custom routes
- app.jsThe 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 DATETIMECreate 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