Bootstrapping
Setting up the web server
Bootstrapping
Overview
To bootstrap your server use the init
method:
bootstrapModule - the init module which use as entry point, contains references to other modules if needed.
rootPath - Server uri prefix
authProvider - the authorization services, more on that on Authorization section
httpsConfiguration - configuration for setting the connection as https (mostly use for - {cert:certificatePath,key:keyPath})
Simple usage
Setting middlewares and Error handlers
For setting static file serving use:
For setting middlewares use:
For setting error handlers use:
Predefined error handler
SugoiJS provides a predefined error handler named (defaultErrorHandler) which provides loggin the error and returning an error to the customer.
Example:
Full example:
Build & listen
After setting the middlewares and error handlers, build and listen to requests by:
This call will return http.Server instance which can be use for setting app variables, socket server and more.
Full example
Retrieving the server app
For retrieving the server application use the HttpServer instance method getServer()
, this method will return the common server application which will allow you to use .get
,.put
,.use
etc..
Example
SugoiJS support migrate existing project by providing hybrid mode.
For achieving this approach use the initializeFrom
method
HttpServer.initializeFrom(sourceApp: TServer, bootstrapModule: any, authProvider?: TNewable<AuthProvider>)
TServer - http.Server | https.Server | { listen: (...args) => any }
Example
Last updated