Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/responders/webworker-responders.js
// @flow | // @flow | ||||
import type { $Request, $Response } from 'express'; | import type { $Request, $Response } from 'express'; | ||||
import path from 'path'; | import path from 'path'; | ||||
function webWorkerResponder(req: $Request, res: $Response): void { | function webWorkerResponder(req: $Request, res: $Response): void { | ||||
let workerPath; | let workerPath; | ||||
let headers = { 'Content-Type': 'application/javascript' }; | let headers = { 'Content-Type': 'application/javascript' }; | ||||
if (req.params.worker === 'notif') { | if (req.params.worker === 'notif') { | ||||
workerPath = 'pushNotif.build.js'; | workerPath = 'pushNotif.build.js'; | ||||
headers = { | headers = { | ||||
...headers, | ...headers, | ||||
'Service-Worker-Allowed': '/', | 'Service-Worker-Allowed': '/', | ||||
tomek: Why do we have to specify this for `notif` worker and not for `database` one? | |||||
kamilAuthorUnsubmitted Done Inline ActionsThe Service-Worker-Allowed header narrows the scope (more detailed scope is specified on registering) from which the Service Worker can intercept requests (where it's a proxy). Shared Worker is not capable of intercepting calls at all, it just exists for the entire origin so there is no need for that, For notifs we use Service Worker, for database we use Shared Worker. kamil: The `Service-Worker-Allowed` header narrows the scope (more detailed scope is specified on… | |||||
}; | }; | ||||
} else if (req.params.worker === 'database') { | |||||
workerPath = 'database.build.js'; | |||||
} | } | ||||
if (!workerPath) { | if (!workerPath) { | ||||
res.sendStatus(404); | res.sendStatus(404); | ||||
return; | return; | ||||
} | } | ||||
const filePath = path.resolve('app_compiled', 'webworkers', workerPath); | const filePath = path.resolve('app_compiled', 'webworkers', workerPath); | ||||
res.sendFile(filePath, { | res.sendFile(filePath, { | ||||
headers, | headers, | ||||
}); | }); | ||||
} | } | ||||
export { webWorkerResponder }; | export { webWorkerResponder }; |
Why do we have to specify this for notif worker and not for database one?