Releases: Potentii/w-srvr
v2.2.1
Locals object
To set the Express app locals object, there is a new method in the main Configurator:
server
.locals({
prop1: 'val1',
prop2: 'val2'
})
// ...
Static options
Now, it's possible to set some of the express.static
options on the add() method of the static configurator. Available options:
- dotfiles
- maxAge
- etag
See: express.static.
v2.2.0
HTTPS Support
W-SRVR now enables you to start a simple HTTPS server with the new https(options, is_file)
method in the main Configurator:
const Configurator = require('w-srvr');
const server = new Configurator();
server
.https({
key: './my-key.key',
cert: './my-cert.crt'
}, true)
.start()
// ...
Check out other examples here.
v2.1.0
Hooks added
Now it is possible to register hook functions for some events, like:
'before-setup'
: It'll be emitted when the internalExpressjs
instance is created, but before it gets configured.'before-api-setup'
: It'll be emitted right before theAPI
resources are set.'after-api-setup'
: It'll be emitted when all theAPI
resources have been set.'before-static-setup'
: It'll be emitted right before thestatic
resources are set.'after-static-setup'
: It'll be emitted when all thestatic
resources have been set.'after-setup'
: It'll be emitted when all the configurations were applied and the server is about to get initialized.
The hook functions for these two events will receive the internal express instance
, and the express module
as arguments.
The Configurator.prototype.on(event, listener)
should be used in order to register listeners for those events.
Example
const Configurator = require('w-srvr');
const server = new Configurator();
server
.port(8080)
.on('before-setup', function(app, express){
// *Do something cool here...
})
.start()
.then(({ address }) => console.log('Server started at ' + address))
.catch(err => console.error(err));
Note: For convenience, the Configurator.HOOKS
enum has all the available hook events names.
404 handling
With the Configurator.prototype.notFound(middleware)
it is now possible to register middlewares to handle 404 NOT FOUND
status
Example
server
.notFound(function(req, res, next){
// *Do something cool here...
});
Index page behaviour changes
Now, when setting the index page of your app, you can choose if this page should be served only at the root route (i.e. http://localhost/), or at all the available routes (i.e. those that normally would return a 404
response). It is useful if you are developing a single page application
with routing control built at the client.
Example
You can add this feature with the root_only
option:
server.static
.index('../src/index.html', { root_only: false }); // Will serve at all the available routes
Note: The initial value is true
(i.e. it serves only at the root route).
Removed unused test files
This version just removed old test files that don't make sense anymore
W-SRVR 2
This release contains a lot of changes:
- Now we have inner configurators (api, static, and advanced-api)
- The spa() method is now called index(), and it is inside the static configurator
- To setup api routes you'll have to use the inner api configurator
- It's now possible to configure headers, and parsers for each api route
For more information, you should read the main README, as it has some examples and links to the detailed documentation.