UNPKG

3.82 kBTypeScriptView Raw
1/// <reference types="express" />
2/// <reference types="node" />
3/// <reference types="winston" />
4/// <reference types="helmet" />
5/// <reference types="pug" />
6import * as Http from "http";
7import * as express from "express";
8import * as winston from "winston";
9import * as helmet from "helmet";
10import { Request, Response, NextFunction, Express } from "express";
11import * as Pug from "pug";
12import { UserInterface } from "./User";
13import { IMain, IDatabase, IOptions } from "pg-promise";
14export interface i18NInterface {
15 [message: string]: {
16 [locale: string]: string;
17 };
18}
19export interface Options {
20 port?: number;
21 address?: string;
22 appLogLevel?: string;
23 maxLogSize?: number;
24 runtimeFolder?: string;
25}
26export declare abstract class HttpApplication {
27 static KEY_RUNTIME_FOLDER: string;
28 static KEY_ROOT_FOLDER: string;
29 static KEY_LOG_FOLDER: string;
30 static KEY_APPLICATION_NAME: string;
31 static KEY_AUTH_USER: string;
32 static KEY_AVAILABLE_LOCALES: string;
33 static KEY_LOCALE: string;
34 static KEY_I18N: string;
35 protected rootFolder: string;
36 protected varFolder: string;
37 protected logFolder: string;
38 protected appName: string;
39 protected options: Options;
40 protected expressApp: Express;
41 protected httpServer: Http.Server;
42 protected logger: winston.LoggerInstance;
43 protected httpErrorViews: any;
44 protected isTestMode: boolean;
45 protected database: IDatabase<any>;
46 protected pgp: IMain;
47 private running;
48 protected abstract configureApplication(): any;
49 constructor(appName: string, rootFolder: string, options?: Options);
50 protected enterTestMode(): void;
51 protected setHttpErrorView(httpStatus: 404 | 500 | 503, viewFullPath: string): void;
52 protected createLogger(): void;
53 private normalizeOptions();
54 protected isDevel(): boolean;
55 protected getEnv(key: string, defValue: any): string;
56 protected configureHelmetSecurity(options?: helmet.IHelmetConfiguration): boolean;
57 private configureHttpLogger();
58 protected createHttpLogger(): string;
59 protected configurePostgreSQLDatabase(host: string, database: string, username: string, password: string, port?: number, options?: IOptions<any>): void;
60 protected configureContentParsers(): boolean;
61 protected configureFilebasedSessionContainer(): boolean;
62 protected configureSessionContainer(): boolean;
63 getCurrentUser(req: Request): UserInterface;
64 setCurrentUser(req: Request, user: UserInterface): void;
65 getAvailableLocales(req: Request): Array<string>;
66 getCurrentLocale(req: Request): string;
67 getContentType(req: Request): string;
68 protected configureAuthenticatedUser(): boolean;
69 getAcceptedLangugeHeader: (req: express.Request) => string;
70 protected configureFileBasedTranslationProvider(folders: Array<string>): void;
71 translate(req: Request, message: string, ...args: any[]): string;
72 protected configureLocaleProvider(parameterName: string, defaultLocale?: string, availableLocales?: Array<string>): boolean;
73 protected configureStaticFolderProvider(folders: any): boolean;
74 protected configureFaciconProvider(faviconPath: string): void;
75 protected configurePugTemplatesProvider(pugOptions?: Pug.Options): void;
76 protected configureApplicationInternal(): boolean;
77 private configure404StatusProvider();
78 protected handleFinalJSONError(err: any, req: Request, res: Response, next: NextFunction): void;
79 protected handleFinalHTMLError(err: any, req: Request, res: Response, next: NextFunction): void;
80 private configureFinalErrorProvider();
81 private createRuntimeFolders();
82 start(done?: Function): void;
83 stop(done?: Function): void;
84 protected onError(error: any): void;
85 protected onStart(): boolean;
86 protected onStop(): void;
87}