new Server()
Server class
- Since
- 1.0.0
- Copyright
- MIT
const {Runtime, Server} = require('@neobeach/core');
const Api = require('./routers/Api');
const server = new Server();
Runtime(() => {
server.includeDefaultBodyParsers();
server.loadRouters([Api]);
server.run();
});Methods
includeDefaultBodyParsers()
Includes/loads default express body parsers (json, text, urlencoded and multer) with recommended config into the Express app
- Since
- 1.0.0
- Copyright
- MIT
const {Runtime, Server} = require('@neobeach/core');
const server = new Server();
Runtime(() => {
server.includeDefaultBodyParsers();
server.run();
});includeDefaultCompression()
Includes/loads default compression (deflate, gzip) with recommended config into the Express app
- Since
- 1.0.0
- Copyright
- MIT
const {Runtime, Server} = require('@neobeach/core');
const server = new Server();
Runtime(() => {
server.includeDefaultCompression();
server.run();
});includeDefaultCookieParser()
Includes/loads cookie parser with recommended config into the Express app
- Since
- 2.1.0
- Copyright
- MIT
const {Runtime, Server} = require('@neobeach/core');
const server = new Server();
Runtime(() => {
server.includeDefaultCookieParser();
server.run();
});includeDefaultCorsHeaders(origin)
Includes/loads default CORS headers with recommended config into the Express app
| Name | Type | Description |
|---|---|---|
origin | String | String with allowed origin URL's |
- Since
- 1.0.0
- Copyright
- MIT
const {Runtime, Server} = require('@neobeach/core');
const server = new Server();
Runtime(() => {
server.includeDefaultCorsHeaders();
server.run();
});includeDefaultSecurityHeaders()
Includes/loads default security headers with recommended config into the Express app
- Since
- 1.0.0
- Copyright
- MIT
const {Runtime, Server} = require('@neobeach/core');
const server = new Server();
Runtime(() => {
server.includeDefaultSecurityHeaders();
server.run();
});loadMiddlewares(middlewares)
Load global middlewares into the Express app
| Name | Type | Description |
|---|---|---|
middlewares | array.<function(*, *, *)> | An array with Express middleware functions |
- Since
- 1.0.0
- Copyright
- MIT
const {Runtime, Server} = require('@neobeach/core');
const server = new Server();
Runtime(() => {
server.loadMiddlewares([
(req, res, next) => {
// Execute custom code here
next();
}
]);
server.run();
});loadRemixFramework(serverBuild)
Attach a Remix Framework build to our Express server
| Name | Type | Description |
|---|---|---|
serverBuild | * | A Remix Server build |
- Since
- 1.0.0
- Copyright
- MIT
import * as serverBuild from "@remix-run/dev/server-build";
const {Runtime, Server} = require('@neobeach/core');
const server = new Server();
Runtime(() => {
server.loadRemixFramework(serverBuild);
server.run();
});loadRouters(routers)
Load routers into the Express app
| Name | Type | Description |
|---|---|---|
routers | array | An array with Routers |
- Since
- 1.0.0
- Copyright
- MIT
const {Runtime, Server} = require('@neobeach/core');
const Api = require('./routers/Api');
const server = new Server();
Runtime(() => {
server.loadRouters([Api]);
server.run();
});loadStatic(directory, prefixopt)
Serves a static directory from the Express app
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
directory | string | Local directory path where the static files live | ||
prefix | string | <optional> | / | Optional prefix to create a virtual path |
- Since
- 1.0.0
- Copyright
- MIT
const {Runtime, Server} = require('@neobeach/core');
const server = new Server();
Runtime(() => {
server.loadStatic('public');
server.run();
});run() → {function}
Starts the Express server
- Since
- 1.0.0
- Copyright
- MIT
- Type:
- function
const {Runtime, Server} = require('@neobeach/core');
const Api = require('./routers/Api');
const server = new Server();
Runtime(() => {
server.run();
});setEJSViewEngine(views)
Sets the Express render engine to EJS
| Name | Type | Description |
|---|---|---|
views | string | Path to the EJS views directory |
- Since
- 2.1.0
- Copyright
- MIT
const {Runtime, Server} = require('@neobeach/core');
const server = new Server();
Runtime(() => {
server.setEJSViewEngine(`${__dirname}/views`);
server.run();
});setParameter(name, value)
Sets an Express app parameter
| Name | Type | Description |
|---|---|---|
name | string | An express parameter name |
value | * | You specified value for the parameter |
- Since
- 1.0.0
- Copyright
- MIT
const {Runtime, Server} = require('@neobeach/core');
const server = new Server();
Runtime(() => {
server.setParameter('title', 'My Site');
server.run();
});