UNPKG

4.26 kBTypeScriptView Raw
1/// <reference types="node" />
2import * as http from 'http';
3import * as https from 'https';
4import * as express from 'express';
5import * as yargs from 'yargs';
6import { ContributionProvider, MaybePromise, Stopwatch } from '../common';
7import { CliContribution } from './cli';
8import { ApplicationPackage } from '@theia/application-package';
9import { ProcessUtils } from './process-utils';
10export declare const BackendApplicationServer: unique symbol;
11/**
12 * This service is responsible for serving the frontend files.
13 *
14 * When not bound, `@theia/cli` generators will bind it on the fly to serve files according to its own layout.
15 */
16export interface BackendApplicationServer extends BackendApplicationContribution {
17}
18export declare const BackendApplicationContribution: unique symbol;
19/**
20 * Contribution for hooking into the backend lifecycle.
21 */
22export interface BackendApplicationContribution {
23 /**
24 * Called during the initialization of the backend application.
25 * Use this for functionality which has to run as early as possible.
26 *
27 * The implementation may be async, however it will still block the
28 * initialization step until it's resolved.
29 *
30 * @returns either `undefined` or a Promise resolving to `undefined`.
31 */
32 initialize?(): MaybePromise<void>;
33 /**
34 * Called after the initialization of the backend application is complete.
35 * Use this to configure the Express app before it is started, for example
36 * to offer additional endpoints.
37 *
38 * The implementation may be async, however it will still block the
39 * configuration step until it's resolved.
40 *
41 * @param app the express application to configure.
42 *
43 * @returns either `undefined` or a Promise resolving to `undefined`.
44 */
45 configure?(app: express.Application): MaybePromise<void>;
46 /**
47 * Called right after the server for the Express app is started.
48 * Use this to additionally configure the server or as ready-signal for your service.
49 *
50 * The implementation may be async, however it will still block the
51 * startup step until it's resolved.
52 *
53 * @param server the backend server running the express app.
54 *
55 * @returns either `undefined` or a Promise resolving to `undefined`.
56 */
57 onStart?(server: http.Server | https.Server): MaybePromise<void>;
58 /**
59 * Called when the backend application shuts down. Contributions must perform only synchronous operations.
60 * Any kind of additional asynchronous work queued in the event loop will be ignored and abandoned.
61 *
62 * @param app the express application.
63 */
64 onStop?(app?: express.Application): void;
65}
66export declare class BackendApplicationCliContribution implements CliContribution {
67 port: number;
68 hostname: string | undefined;
69 ssl: boolean | undefined;
70 cert: string | undefined;
71 certkey: string | undefined;
72 projectPath: string;
73 configure(conf: yargs.Argv): void;
74 setArguments(args: yargs.Arguments): void;
75 protected appProjectPath(): string;
76}
77/**
78 * The main entry point for Theia applications.
79 */
80export declare class BackendApplication {
81 protected readonly contributionsProvider: ContributionProvider<BackendApplicationContribution>;
82 protected readonly cliParams: BackendApplicationCliContribution;
83 protected readonly app: express.Application;
84 protected readonly applicationPackage: ApplicationPackage;
85 protected readonly processUtils: ProcessUtils;
86 protected readonly stopwatch: Stopwatch;
87 constructor(contributionsProvider: ContributionProvider<BackendApplicationContribution>, cliParams: BackendApplicationCliContribution);
88 protected initialize(): Promise<void>;
89 protected configure(): Promise<void>;
90 use(...handlers: express.Handler[]): void;
91 start(aPort?: number, aHostname?: string): Promise<http.Server | https.Server>;
92 protected onStop(): void;
93 protected serveGzipped(contentType: string, req: express.Request, res: express.Response, next: express.NextFunction): Promise<void>;
94 protected measure<T>(name: string, fn: () => MaybePromise<T>): Promise<T>;
95 protected handleUncaughtError(error: Error): void;
96}
97//# sourceMappingURL=backend-application.d.ts.map
\No newline at end of file