1.4.6 • Published 3 months ago

expressjs-app v1.4.6

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

ExpressJS API - Custom Implementation

: This project was intially developed to customized and ease the usage of configuring express framework.


Installation

npm install expressjs-app

Usage

const { ExpressApi, LogOption } = require("expressjs-app")

const app = (router, ...args) => {
    router.get('/', (req, res) => {
        res.json({
            status: 200,
            message: "Hello, Shits!"
        })
    })

    return router
}

const headers = (req, res, next) => {
    res.set('Access-Control-Allow-Methods', 'GET,POST');
    next()
}

const unauthorize = (err, req, res, next) => {
    if (err.name === 'AuthenticationError') {
        // Send a customized response for authentication failure
        return res.status(err.status).json({ 
            status: err.status,
            message: 'Invalid Authorization header supplied.\nPlease contact support or check your credentials.'
        })
    }

    next()
}

const apiOptions = { 
    enableCors: true, 
    // lastRouteHandler: invalid, // Method for handling 404 not found routes
    // docsModule: swaggerDoc, // Swagger Docs
    enableLog: true, // Log option can also accept LogOption { path: '/logs' }
    // jwtStrategy: jwtStrategy // JWT Strategy, this package uses passport-jwt for authentication, if this provided as option make sure you enable `registerAuthenticationRoute`
}

const apiInstance = new ExpressApi(apiOptions)
apiInstance.registerRoutesGroup(
        "/api",
        {
            method: app, args: undefined, name: 'app'
        }
    )
    .registerMiddlewares(headers, unauthorize)
    // Start the API/App
    .start(async () => {
        console.log('Server Started')
    })

Configuration

NODE_ENV=staging
API_BASE_PATH=/
SECRET_KEY=pass123!
PORT=3000

# OPTIONAL
LOG_FORMAT=combined # default 'combined',
LOG_SIZE='10M' # default '10M',
LOG_INTERVAL='1d' # default '1d',
LOG_MAX_FILES=10 # default 10
1.4.6

3 months ago

1.4.5

3 months ago

1.4.4

3 months ago

1.4.3

3 months ago

1.3.7

6 months ago

1.4.2

6 months ago

1.4.1

6 months ago

1.4.0

6 months ago

1.3.9

6 months ago

1.3.8

6 months ago

1.3.6

1 year ago

1.3.5

1 year ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago