Introduction

OstroJS has a built-in http server that supports NodeJS http1 and http2. @ostro/server is lightweight, quick, and customisable. You don't have to worry about server exceptions since OstroJS's built-in exception handler will take care of them.

Configuration

The server configuration file for your application is config/app.js. 127.0.0.1 and 8000 will be the default server host and port, respectively. You may change the host and port using config/app.js or server start settings to suit your needs.

Boostraping

Bootstrapper will assist you in getting your app ready. Using bootstrapper, the server will gather the required information about the application, allowing you to immediately run the kernel handler to handle application route callbacks.

Application

All provider and load configuration are invoked by the application, which aids in the sharing of information among all providers.

const app = new(require('@ostro/foundation/application'))(process.cwd())

module.exports = app

You may use the Application instance to supply your own framework directory. Support your app.js in the bin directory, then pass the framework directory as a parameter to the application class.

const app = new(require('@ostro/foundation/application'))(path.resolve('..'))

module.exports = app

Custom Server Options

If no option to start a server callback is provided, the OstroJS server will choose server information from app.js.

const app = require('./bootstrap/app')

let server = app.make('@ostro/server',app.config.app);

server.start(callback)

If you don't provide any arguments for server start, OstroJS will use the server's default callback and options.

const app = require('./bootstrap/app')

let server = app.make('@ostro/server',app.config.app);

server.start()

If you pass server config options as json object.

const app = require('./bootstrap/app')

let server = app.make('@ostro/server',app.config.app);

server.start({})

 

Server Callback

OstroJS pass server context as argument to callback. You can access server instance, host and port.

const app = require('./bootstrap/app')

let server = app.make('@ostro/server',app.config.app);

server.start(function({ host, port, server }) {
    console.log('\x1b[36m%s\x1b[0m', `----------------------------------------`);
    console.log('\x1b[36m%s\x1b[0m', `Application Started`);
    console.log('\x1b[36m%s\x1b[0m', `Environment: ${app.config.get('app.env')}`);
    console.log('\x1b[36m%s\x1b[0m', `Application Running on ${path.isAbsolute(port.toString())?'pipe : '+port:': '+host + ':' + port}`)
    console.log('\x1b[36m%s\x1b[0m', `----------------------------------------`);
})