1.1.5 • Published 8 months ago

@fleitor/fl-back v1.1.5

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

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
1.1.5

8 months ago

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

2 years ago

1.1.1

2 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago