- Removed legacy servertools and Express dependencies in favor of SmartServe. - Introduced DevToolsHandler and TypedRequestHandler for handling specific routes. - Added support for custom route registration with regex parsing. - Implemented sitemap and feed handling with dedicated helper classes. - Enhanced HTML response handling with reload script injection. - Updated UtilityServiceServer and UtilityWebsiteServer to utilize new TypedServer API. - Removed deprecated compression options and Express-based route handling. - Added comprehensive request handling for various endpoints including robots.txt, manifest.json, and sitemap. - Improved error handling and response formatting across the server.
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { TypedServer } from '../classes.typedserver.js';
|
|
|
|
export interface ILoleServiceServerConstructorOptions {
|
|
addCustomRoutes?: (typedserver: TypedServer) => Promise<any>;
|
|
serviceName: string;
|
|
serviceVersion: string;
|
|
serviceDomain: string;
|
|
port?: number;
|
|
}
|
|
|
|
// the main service server
|
|
export class UtilityServiceServer {
|
|
public options: ILoleServiceServerConstructorOptions;
|
|
public typedServer: TypedServer;
|
|
|
|
constructor(optionsArg: ILoleServiceServerConstructorOptions) {
|
|
this.options = optionsArg;
|
|
}
|
|
|
|
public async start() {
|
|
console.log('starting lole-serviceserver...');
|
|
this.typedServer = new TypedServer({
|
|
cors: true,
|
|
domain: this.options.serviceDomain,
|
|
forceSsl: false,
|
|
port: this.options.port || 3000,
|
|
robots: true,
|
|
defaultAnswer: async () => {
|
|
const InfoHtml = (await import('../infohtml/index.js')).InfoHtml;
|
|
return (
|
|
await InfoHtml.fromSimpleText(
|
|
`${this.options.serviceName} (version ${this.options.serviceVersion})`
|
|
)
|
|
).htmlString;
|
|
},
|
|
});
|
|
|
|
// Add any custom routes
|
|
if (this.options.addCustomRoutes) {
|
|
await this.options.addCustomRoutes(this.typedServer);
|
|
}
|
|
|
|
await this.typedServer.start();
|
|
}
|
|
|
|
public async stop() {
|
|
await this.typedServer.stop();
|
|
}
|
|
}
|