SAP simple configuration driven application server based on Express
SAP Application Server encapsulates all the complex logic of server initialization (database connection, dynamic service loading, Express application creation and configuration...). Everything is based on a server configuration JSON file.
Only a few lines of code are required to create an executable application
var path = ;var Server = Server;Serverstartpath; // use absolute path for config file
The server configuration file is a JSON file made of a number of sections, each section being a JSON object or the path to the JSON file containing the section definition (paths are relative to the configuration file). You may refer to the SAP configuration file for a comprehensive example.
This section defines the connection parameters to MongoDB
This section controls the activation of various debug features (currently only live-reload)
This section controls the SAP deployment strategy in MongoDB through the strategy parameter
This section allows a simple definition of environment variables which will be set on the node process (e.g. setting NODE_ENV to 'production').
This section defines some HTTP server parameters
proxy subsection of http section defines global proxy configuration for outbound http calls
express subsection of http section defines Express configuration parameters
Defines Express application settings.
app.set(key, value) will called for each (key, value) pair
Defines TLS configuration for the server, cf. http://nodejs.org/api/tls.html
Defines the base path to resolve certificate and key files (default is config.json location)
Path to a file containing the private key, certificate and CA certs of the server in PFX or PKCS12 format. (Mutually exclusive with the key, cert and ca options.)
Path to a file containing the private key of the server in PEM format.
A string of passphrase for the private key or pfx.
Path to a file containing the certificate key of the server in PEM format. (Could be an array of file paths).
A file location or an array of file locations for the server trusted certificates in PEM format. If this is omitted several well known "root" CAs will be used, like VeriSign. These are used to authorize connections.
A file location or an array of file locations for the pointing to PEM encoded CRLs (Certificate Revocation List)
This section defines the server logging configuration
This section defines server parameters
This section defines the list of server services to load and the mount point of their http handlers.
For each server module, you should define a mounting configuration
A SAP server module.exports should return an object exposing the following optional methods
Mounting configuration may be a string containing the path at which all module handlers will be mounted (convenient for services exposing a single handler) or a hash defining for each handler name the mounting path.
Apart from the getHandlers callback which is always synchronous, all callback may be either synchronous or asynchronous. If the method exposed by the service takes no parameter it must be a synchonous one. Otherwise, it is considered asynchronous and must take as unique parameter a standard callback function cb(err). In that case, the server will pause and wait for the callback before resuming initialization.
This section controls the static web content
It’s possible to start the server so to run some schema operations: checkSchema, initSchema, upgradeSchema
var path = ;var AppServer = ;var server = path;server
Once the operation is completed, the server is shut down.
When running checkSchema, if implemented by services, these methods are called in this order: checkSchema(), then onSchemaChecked()
When running initSchema: initSchema(), then onSchemaInitialized(), then checkSchema(), then onSchemaChecked()
When running upgradeSchema: prepareUpgrade(), then upgradeSchema(), then onSchemaUpgraded(), then checkSchema(), then onSchemaChecked()