Return Http.Server instance.
Return Https.Server instance.
Return the injectorService initialized by the server.
Return the InjectorService initialized by the server.
Return the settings configured by the decorator @ServerSettings.
This method let you configure the middleware required by your application to works.
Add classes to the components list
Add classes decorated by @Controller()
to components container.
@Controller('/ctrl')
class MyController{
}
new ServerLoader().addControllers('/rest', [MyController])
?> If the MyController class isn't decorated, the class will be ignored.
Create a new HTTP server with the provided port
.
Create a new HTTPs server.
options
port
<number>: Port number,key
<string> | <string[]> | <Buffer> | <Object[]>: The private key of the server in PEM format. To support multiple keys using different algorithms an array can be provided either as a plain array of key strings or an array of objects in the format {pem: key, passphrase: passphrase}
. This option is required for ciphers that make use of private keys.passphrase
<string> A string containing the passphrase for the private key or pfx.cert
<string> | <string[]> | <Buffer> | <Buffer[]>: A string, Buffer, array of strings, or array of Buffers containing the certificate key of the server in PEM format. (Required)ca
<string> | <string[]> | <Buffer> | <Buffer[]>: A string, Buffer, array of strings, or array of Buffers of trusted certificates in PEM format. If this is omitted several well known "root" CAs (like VeriSign) will be used. These are used to authorize connections.See more info on httpsOptions.
Options to create new HTTPS server.
Proxy to express engine
Initialize configuration of the express app.
Mount all controllers files that match with globPattern
(Glob Pattern)
under the endpoint. See Versioning Rest API for more informations.
Scan and imports all files matching the pattern. See the document on the Glob pattern for more information.
import {ServerLoader} from "@tsed/common";
import Path = require("path");
export class Server extends ServerLoader {
constructor() {
super();
let appPath = Path.resolve(__dirname);
this.scan(appPath + "/controllers/**\/**.js")
}
}
Theses pattern scan all files in the directories controllers, services recursively.
!> On windows on can have an issue with the Glob pattern and the /. To solve it, build your path pattern with the module Path.
const controllerPattern = Path.join(rootDir, 'controllers','**','*.js');
Proxy to express set
Start the express server.
Create a new server from settings parameters.
This method let you to add a express middleware or a Ts.ED middleware like GlobalAcceptMimes.
@ServerSettings({
rootDir,
acceptMimes: ['application/json'] // optional
})
export class Server extends ServerLoader {
$onMountingMiddlewares(): void|Promise<any> {
const methodOverride = require('method-override');
this.use(GlobalAcceptMimesMiddleware)
.use(methodOverride());
// similar to
this.expressApp.use(methodOverride());
// but not similar to
this.expressApp.use(GlobalAcceptMimesMiddleware); // in this case, this middleware will not be added correctly to express.
return null;
}
}
Generated using TypeDoc
Return Express Application instance.