Skip to content

owliehq/buboJS

Repository files navigation

MIT License Commitizen friendly semantic-release: angular

api version tinyHttp sequelize validation http error acl uploader firebase uploader S3 jwt auth swagger

BuboJs is a library to build quickly and efficiently a Rest API, it is based on NodeJS, written entirely in Typescript and using ESModules. Main Features:

  • Automatic route building with a direct link to the database (PostGres)
  • Integrated role management tools
  • File upload and download tools (firebase)
  • Route validation tools

Contribution

Install

Install modules using lerna bootstrap to centralize all modules in root node_modules.

lerna bootstrap

Build

It's necessary to build ts files into js files to execute them This command remove previous build dir and build them with tsc compiler

yarn build

Run tests

Jest run all *.test.ts files in packages/* dir ⚠️You should build packages to execute tests⚠️

yarn test

Usage

Starting server

To start the server you must instantiate an HttpAdapter (currently only tinyhttp is available) Then to actually start the server you have to pass this instance and the options you need to the app.initHttpModule()

example:

import { TinyHttpAdapter } from '@bubojs/tinyhttp'
import { app, AppOptions } from '@bubojs/api'

export const startServer = () => {
  return new Promise(async (resolve, reject) => {
    try {
      const adapter = new TinyHttpAdapter()
      const appOptions: AppOptions = {
        errorMiddleware: (err: any, req: any, res: any, next?: Function) => {
          console.log('Caught Server Error ', err)
          res.status(500).json(err)
        },
        port: 3000
      }
      const server = await app.initHttpModule(adapter, appOptions)
      resolve(server)
    } catch (err) {
      reject(err)
    }
  })
}

Controllers

Api

Route validator

Fastest Validator

Files managers

Firebase

Amazon S3

Authentication and rights

To manage authentication currently only JWT is available but you can add your authentication system and others will be added later

For the rights, the library role-acl is used

Authentication

JWT

Rights

Access Control List

Database management

Sequelize

Middleware customs

You can define your own middlewares, they can be called before or after the execution of the route, for the middlewares that run after the route there is no need to send the result, this can be done automatically because bubo adds itself a last middleware that returns what is in req.result

The middlewares are executed in the same order as they are added in the code (the highest one above the route will be executed first)

Before Middleware

TODO

After Middleware

TODO

Editor

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 5

Languages