UNPKG

@petro-kushchak/homebridge-homepod-radio

Version:

Homebridge accessory for streaming radio to Homepod Mini and Apple TV

31 lines 924 B
import http from 'http'; export class HttpService { httpPort; logger; server; constructor(httpPort, logger) { this.httpPort = httpPort; this.logger = logger; this.logger.info('Setting up HTTP server on port ' + this.httpPort + '...'); this.server = http.createServer(); } stop() { this.server.close(); } async start(httpHandler) { this.server.listen(this.httpPort); this.server.on('request', async (request, response) => { let result = { error: true, message: 'Malformed URL.', }; if (request.url) { result = await httpHandler(request.url); } response.writeHead(result.error ? 500 : 200); response.write(JSON.stringify(result)); response.end(); }); } } //# sourceMappingURL=httpService.js.map