@fleitor/fl-back

1.1.5 • Public • Published

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 routes
  • app.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

Readme

Keywords

none

Package Sidebar

Install

npm i @fleitor/fl-back

Weekly Downloads

0

Version

1.1.5

License

ISC

Unpacked Size

83.7 kB

Total Files

31

Last publish

Collaborators

  • mikpetr