0.1.4 • Published 6 years ago

nbs_framework v0.1.4

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

A node framework built on top of express

Aims

  1. To remove a lot of express boilerplate through standardisation (authentication, routing)
  2. To provide an easy SQL interface ie ( db.query(SQL, params) )
  3. To remain fast and simple

Install

yarn add nbs_framework npm install nbs_framework --save

Example

/index.js

const nbs = require('nbs_framework')

const config = {
    host: {
        port: 8080
    },
    webroot: "www",
    response_headers: {
        "Access-Control-Allow-Origin": "*"
    },
    auth: {
        cookie_name: "auth",
        session_expires: 60*60,
        cookie_options: {
            maxAge: 60*60
        },
        keys: {
            "aes": "mySecretKey"
        },
        public_urls: ['/api/login']
    }
}

const server = new nbs.Server(config)
    .initAuth()
    .route('post', '/api/login')

/api/login.js

module.exports = {
    POST: function(params) {
        if ( params.username !== "mySecretName" || params.password != "mySecretPassword" ) {
            return this.respond({ok: false}, 403)
        }

        let session_token = this.server.auth.createToken({ username: params.username, loggedin: true }, "aes")

        this.cookie(this.server.config.auth.cookie_name, session_token)

        this.respond({ok: true})
    }
}
0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago