Skip to content

FireStorm Object

Hayley edited this page Sep 29, 2020 · 6 revisions

The FireStorm object is the core logic to the framework. It registers your routes and error pages as well as runs the web server. For an example

int main() {
  FireStorm()
    .add_route(new UserDefinedRoute())
    .add_route(new AnotherUserDefinedRoute())
    .log_level(Warning)  // Optional
    .error_handler(HTTP_STATUS_NOT_FOUND, custom_error_hander)  // Optional
    .ignite();
  return 0;
}

Registering routes

Routes can be registered using the add_route() method (see above for an example). The order in which the routes are added is preserved meaning that they will be executed in the same order when the server receives a request.

Setting the log level

The logging level can be set using the log_level() method by passing it a LogLevel variant. The default log level is Debug.

Running the web server

The ignite() method can be used to start the web server. The ignite() method has the following signature

void ignite(unsigned int port=5000, string host="localhost");

where port is the TCP port to listen for requests on and host specifies what host to listen on. The host is to ensure that the web server cannot be accidentally exposed on alternate host names although system administrators should always ensure that firewall rules are in place such that this feature is only used as a last line of defence.

Custom error pages

All custom error page handlers must be a valid ErrorFn where ErrorFn is defined as

using ErrorFn = Response (*)();

For an example the default 404 handler is as follows

Response not_found_fn() { 
  return plain("Not Found", HTTP_STATUS_NOT_FOUND);
}

Custom error pages can be registered by passing a ErrorFn and the corresponding http_status_code to the error_handler() method.

Clone this wiki locally