marko-starter-express-server

1.0.7 • Public • Published

marko-starter-express-server

A marko-starter plugin which uses Express as it's server instance, and provides additional functionality to configure the Express instance prior to server initialization.

Usage

The most simple way to use the plugin, which provides the stock standard ExpressJS instance, with the files routed through identical to the method done in the default marko-starter package.

project.js

module.exports = marko_starter.projectConfig({
  plugins: ["marko-starter-express-server"]
});  

For more unique and customised requirements using express, it is possible to pass an instantiation of the plugin, with passing a server configure object:

project.js

var express_plugin = require("marko-starter-express-server").config(require("./express_config"));

module.exports = marko_starter.projectConfig({
  plugins: [express_plugin]
});  

The config object expected to be passed:

{
  <METHOD> : [<METHOD OBJECT>] | <METHOD OBJECT>,
  'use' : [<METHOD OBJECT> | <FUNCTION>] | <FUNCTION> | <METHOD OBJECT>,
  'routes' : [<ROUTE OBJECT>],
  'params' : [<PARAM OBJECT>]
}

All fields are optional.

  • METHOD: ... This is the expected HTTP method, the list of supported methods can be found here under Routing methods. ... This field replicates the behaviour of the app.METHOD() in ExpressJS.
  • METHOD OBJECT: ...The route object has the following structure:
{
  'path' : <PATH>,
  'callbacks': [<FUNCTION>] | <FUNCTION>
}

... The path expected is the same as that used in ExpressJS, and can be found here, included in this is the 'all' functionality of ExpressJS.

  • use ... The objects/functions passed under this parameter, are applied to the ExpressJS object, the same as the use method as per app.use()
  • ROUTE OBJECT: ... The route object has the following structure:
{
  'path' : <PATH>,
  <METHOD>: [<FUNCTION>] | <FUNCTION>
}

... Similar to the METHOD OBJECT, the path is expected in the same format as here. ... With the METHOD expected to be like that of METHOD, and also including the all function.

  • params ... The objects passed within this property, are applied to the ExpressJS server instance the same as app.param().
  • PARAM OBJECT ... The param object has the following structure:
{
  'name' : [<STRING>] | <STRING>,
  'callbacks': <FUNCTION>
}

... The fields of this object are the same as here.

Limitations

Currently there are several limitations that the plugin does not yet implement, or implements poorly. I'll probably get around to fixing them.

  • Does not permit passing an existing instance of ExpressJS
  • Does not accept an ExpressJS route object
  • Has not method to specify the order of the Method calls (this has the impact that if someone wants the all callback done at the end of a particular route/path this can't be done).
  • Hooks to do "customisation" before start, after start, or during particular times in the initialisation of the ExpressJS instance.
  • The Methods are case sensitive, and need to be lower case.

This list is hardly exhaustive, and is based off of my own personal experience, and will likely be extended if people start using it.

Readme

Keywords

none

Package Sidebar

Install

npm i marko-starter-express-server

Weekly Downloads

1

Version

1.0.7

License

MIT

Last publish

Collaborators

  • maraket