SFrontendServer modules
The SFrontendServer is based on the AMAZING ExpressJs server. This mean that you can extend it as you want by following these steps described bellow:
Built-in modules
Our server comes with some built-in modules. Here's the list:
404
: This module handle the 404 by rendering either your 404 page configured in the pages or the default 404 pagepublicDir
: This module allows you to serve files from the public directoryupload
: This module allows you to upload files to the tmp/upload directorygeneric
: This module gives you access to the "generic" handler that renders dynamically views from your page configdocmap
: This module gives you access to a "docmap" object in the viewsclassmap
: This module gives you access to the /classmap.json urlcarpenter
: This module gives you access to a "carpenter" object in the viewsredirect
: This module allows you to make redirections depending on requested pathconfig
: This module gives you access to a "config" and a "configFiles" object into the viewsfrontspec
: This module gives you access to a "frontspec" object into the views
Create your module
First of all, create a file (where you want) src/node/myModule.ts
that will be the entry point of your module.
Here's the scaffold content that you can copy and past in your file:
You module default exported function will be called with an object containing these data:
express
: The express instance used for the server on which you can register new routes, etc...settings
: The settings object specified in thefrontendServer.config.ts
file alongside your module path.config
: The fullfrontendServer.config.ts
configuration object.startParams
: The parameters passed to theSFrontendServer.start
method.
Register your module
To to register your module, simply add it to the config.frontendServer.modules
by creating a file under .sugar/frontendServer.config.ts
like this:
For more information about configuring your server, check out the next doc that talk about
handlers
,middleware
androutes
.