fix(core): update
This commit is contained in:
51
ts/classes.serviceserver.ts
Normal file
51
ts/classes.serviceserver.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import { InfoHtml } from './infohtml/index.js';
|
||||
|
||||
export interface IServiceServerConstructorOptions {
|
||||
addCustomRoutes?: (serverArg: plugins.typedserver.servertools.Server) => Promise<any>;
|
||||
serviceName: string;
|
||||
serviceVersion: string;
|
||||
serviceDomain: string;
|
||||
port?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* a server for serving your app to the outside world
|
||||
*/
|
||||
export class ServiceServer {
|
||||
public options: IServiceServerConstructorOptions;
|
||||
public typedServer: plugins.typedserver.TypedServer;
|
||||
|
||||
constructor(optionsArg: IServiceServerConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
public async start() {
|
||||
console.log('starting lole-serviceserver...')
|
||||
this.typedServer = new plugins.typedserver.TypedServer({
|
||||
cors: true,
|
||||
domain: this.options.serviceDomain,
|
||||
forceSsl: false,
|
||||
port: this.options.port || 3000,
|
||||
robots: true,
|
||||
defaultAnswer: async () => {
|
||||
return (
|
||||
await InfoHtml.fromSimpleText(
|
||||
`${this.options.serviceName} (version ${this.options.serviceVersion})`
|
||||
)
|
||||
).htmlString;
|
||||
},
|
||||
});
|
||||
|
||||
// lets add any custom routes
|
||||
if (this.options.addCustomRoutes) {
|
||||
await this.options.addCustomRoutes(this.typedServer.server);
|
||||
}
|
||||
|
||||
await this.typedServer.start();
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
await this.typedServer.stop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user