App - jellyfishsolutions/lynx GitHub Wiki
App class
the App class is the entry point of a Lynx application.
Once created, it dynamically load all the modules and their features (controllers, middleware, etc..).
Index
Properties
customResizeFunction: ResizeFunction | null
Allows to customize the image resizing function, that will be executed automatically when a new file is downloaded. The cache system will automatically work; this function shall only execute the image resizing.
customErrorController: ErrorController
This property allow the customization of the standard error controller.
It is necessary to overriding the standard methods available in the ErrorController class, in order to customize the standard error management behaviour.
Methods
async executeMigrations()
This method will execute the migrations. By default, this method will be executed automatically during the app startup.
startServer(port: number)
Starting the http server on the specified port.
Parameters:
- port: the listening port of the http server
route(name: string, parameters?: any)
Proxy method to the usual route method available from the controller
Parameters:
- name: the name of the route
- parameters: an object containing the parameters of the route
translate(str: string, req: express.Request, language?: string)
This method request the translation of a string in a current request. It returns the translated string, or the same input string if no translation is found.
Parameters:
- str: the string to be translated
- req: the request from which infer the language
- language: optionally, the language can be forced using this variable
This method could also be called without a req context. In this case, it is necessary to provide an empty non-null object as the request, with the appropriate cast to any:
app.translate('string_to_translate', {} as any, 'it');
translateFormat(str: string, req: express.Request, language: string | undefined, ...args: any)
This method request the translation of a string in a current request, adding also formatted arguments. It returns the translated string, or the same input string if no translation is found, with the formatted arguments.
Each argument should be encoded as {0}, {1}, etc...
Parameters:
- str: the string key to be translated
- req: the original request
- language: optionally, the language can be forced using this variable
- args: the arguments to format the string
As for the non-formatted version, this method could also be called without a req context. In this case, it is necessary to provide an empty non-null object as the request, with the appropriate cast to any.
Example: en.json:
{
"welcome_msg": "Hi {0}! Welcome to our dashboard!"
}
From typescript:
app.translateFormat('welcome_msg', req, 'it', user.name);
generateTokenForUser(user: User): string
Utility method to generate a user token (JWT) using the secret defined in the configuration.
Parameters:
- user the user