Changeset View
Standalone View
keyserver/src/responders/webworker-responders.js
- This file was added.
// @flow | |||||
import type { $Request, $Response } from 'express'; | |||||
import path from 'path'; | |||||
export function webWorkerResponder(req: $Request, res: $Response) { | |||||
kamil: I think in all files for responders we have functions definition and then at the bottom of the… | |||||
let workerPath; | |||||
let options = {}; | |||||
if (req.params.worker === 'notif') { | |||||
kamilUnsubmitted Not Done Inline ActionsShouldn't we return a different status code when the worker param is not defined at all? (400 or 422 comes to mind but not sure) kamil: Shouldn't we return a different status code when the `worker` param is not defined at all? | |||||
michalAuthorUnsubmitted Done Inline ActionsIn express route parameters can't be null or undefined. So currently it will just redirect to our '*' route returns the web app. We could probably handle it with additional routes for 'worker' and 'worker/' but I'm not sure if that's worth it. michal: In express route parameters can't be null or undefined. So currently it will just redirect to… | |||||
workerPath = 'pushNotif.build.cjs'; | |||||
options = { | |||||
headers: { | |||||
'Content-Type': 'application/javascript', | |||||
'Service-Worker-Allowed': '/', | |||||
kamilUnsubmitted Not Done Inline ActionsProbably I'll be better to leave the default scope. If I understand correctly notifs feature will not have to intercept calls to the network, so there is no need for broad scope - that being said we can have only one SW per scope and if we will want to introduce SW in the future which will intercept network calls we will need to move this one (which seems more complicated than just changing scopes). Looks like the default scope, without the header or specifying sth like `'Service-Worker-Allowed': '/push-notifs', and then registering SW in the same scope on the client will be sufficient. kamil: Probably I'll be better to leave the default scope. If I understand correctly notifs feature… | |||||
}, | |||||
}; | |||||
} | |||||
if (!workerPath) { | |||||
res.sendStatus(404); | |||||
return; | |||||
} | |||||
res.sendFile(path.resolve('app_compiled', 'webworkers', workerPath), options); | |||||
} |
I think in all files for responders we have functions definition and then at the bottom of the file export { instead of inline.
Also, maybe the return type will be better for clarity.