Skip to content

Releases: Potentii/w-srvr

v2.2.1

31 Jul 22:31
Compare
Choose a tag to compare

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

30 Jul 17:03
Compare
Choose a tag to compare

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

15 Mar 04:23
Compare
Choose a tag to compare

Hooks added

Now it is possible to register hook functions for some events, like:

  • 'before-setup': It'll be emitted when the internal Expressjs instance is created, but before it gets configured.
  • 'before-api-setup': It'll be emitted right before the API resources are set.
  • 'after-api-setup': It'll be emitted when all the API resources have been set.
  • 'before-static-setup': It'll be emitted right before the static resources are set.
  • 'after-static-setup': It'll be emitted when all the static 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).

See: Configurator.prototype.index(file, options).

Removed unused test files

09 Mar 15:46
Compare
Choose a tag to compare

This version just removed old test files that don't make sense anymore

W-SRVR 2

07 Mar 16:30
Compare
Choose a tag to compare

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.

v1.1.1

06 Mar 18:22
Compare
Choose a tag to compare
Minor correction in the documentation