The StaticConfigurator
class provides methods to register static resources in the server as well as an index page. An instance of this configurator can be found with the Configurator.prototype.static
property:
const server = new Configurator();
// *Getting the static configurator:
let static_configurator = server.static;
string - The index file path (absolute)
Note: readonly, use the index()
method to assign a value.
Array<{ route, path }> - An array containing all the static resources
route
string - The server routepath
string - The absolute path to a file/directory in disk
Note: readonly, use the add()
method to add a new resource.
Sets the main HTML file
Note: By default, the given file will be served only on the root route (i.e. http://localhost/).
file
string - The relative/absolute file pathoptions
object - [optional] Aditional options, the following properties can be set:options.root_only
boolean - It sets whether the index file should be served only at the root route ('/'
), or at all available routes (initial value istrue
)
StaticConfigurator - This same configurator (for method chaining)
- TypeError - If the file is not a string
- Error - If the file does not represent a path to a file
server.static
.index('../src/my_index.html', { root_only: true });
Registers a static directory or file to be served on the given route
route
string - The server routeresource_path
string - The relative/absolute file/directory pathoptions
object - The static options objectoptions.dotfiles
string - Express staticdotfiles
propertyoptions.maxAge
number - Express staticmaxAge
propertyoptions.etag
boolean - Express staticetag
property
StaticConfigurator - This same configurator (for method chaining)
- TypeError - If the resource path is not a string
server.static
.add('/static/js', '../src/js')
.add('/static/css', '../src/css', { dotfiles: 'allow' })
.add('/static/logo', '../src/images/logo.png');
Retrieves the main configurator
Configurator - The main configurator (for configurator chaining)
// *Main 'Configurator' object:
server
.port(...)
.static
// *Inner 'StaticConfigurator' object:
.index(...)
.add(...)
.add(...)
.done() // Returns the chain back to the main configurator
// *Main 'Configurator' object:
.start();