diff --git a/keyserver/src/keyserver.js b/keyserver/src/keyserver.js --- a/keyserver/src/keyserver.js +++ b/keyserver/src/keyserver.js @@ -24,6 +24,7 @@ markVersionDeployedResponder, } from './responders/version-responders.js'; import { websiteResponder } from './responders/website-responders.js'; +import { webWorkerResponder } from './responders/webworker-responders.js'; import { onConnection } from './socket/socket.js'; import { multerProcessor, @@ -119,6 +120,7 @@ // $FlowFixMe express-ws has side effects that can't be typed router.ws('/ws', onConnection); + router.get('/worker/:worker', webWorkerResponder); router.get('*', htmlHandler(websiteResponder)); router.post( diff --git a/keyserver/src/responders/webworker-responders.js b/keyserver/src/responders/webworker-responders.js new file mode 100644 --- /dev/null +++ b/keyserver/src/responders/webworker-responders.js @@ -0,0 +1,26 @@ +// @flow + +import type { $Request, $Response } from 'express'; +import path from 'path'; + +function webWorkerResponder(req: $Request, res: $Response): void { + let workerPath; + + if (req.params.worker === 'notif') { + workerPath = 'pushNotif.build.cjs'; + } + + if (!workerPath) { + res.sendStatus(404); + return; + } + + const filePath = path.resolve('app_compiled', 'webworkers', workerPath); + res.sendFile(filePath, { + headers: { + 'Content-Type': 'application/javascript', + }, + }); +} + +export { webWorkerResponder };