Suppress Server#
The suppress server is a wrapper around the express.js app object. To construct the server, you do not need any parameters. The server will be constructed with the default settings.
const { SuppressServer } = require('ai.suppress.js');
const server = new SuppressServer();
Methods#
start()#
Starts the server. This method does not return anything and takes one optional parameter, port. If no port is specified, the server will start on port 3000.
server.start(3000);
createEndpoint(path, method, generator)#
Creates an endpoint on the server. This method takes three parameters, path, method, and generator.
pathis the path of the endpoint. This can be a string or a regular expression.methodis the HTTP method of the endpoint. This should be a string, with the value being one ofGET,POST,GET-db,POST-db,PUT-db.generatoris the generator function that will be called when the endpoint is hit. This should be theDataGeneratorobject.
server.createEndpoint('/test', 'GET', generator);
mountDatabase(dataStorage)#
Mounts a database to the server. This method takes one parameter, dataStorage, which is the DataStorage object that will be mounted to the server. Learn more about the DataStorage object here.
server.mountDatabase(dataStorage);
Customization#
You can add custom endpoints and middleware to the server. To do this, you can access the app property of the server object. This is the express.js app object.
server.app.get('/test', (req, res) => {
res.send('Hello World!');
});
Middle-ware can be added in a similar way.
server.app.use((req, res, next) => {
console.log('Request received!');
next();
});