Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/responders/website-responders.js
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | async function getAssetInfo() { | ||||
} catch { | } catch { | ||||
throw new Error( | throw new Error( | ||||
'Could not load assets.json for web build. ' + | 'Could not load assets.json for web build. ' + | ||||
'Did you forget to run `yarn dev` in the web folder?', | 'Did you forget to run `yarn dev` in the web folder?', | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
let pushApiPublicKey: ?string = null; | |||||
async function getPushApiPublicKey() { | |||||
ashoat: It looks like we're introducing one use case right now where we need to open this file to… | |||||
if (pushApiPublicKey) { | |||||
return pushApiPublicKey; | |||||
} | |||||
try { | |||||
const keysString = await readFile('secrets/web_push_config.json', 'utf8'); | |||||
ashoatUnsubmitted Not Done Inline ActionsBy circumventing the importJSON framework that we use for all other imports, you're making this impossible to configure on prod. Whenever you are doing something that has been done before, please spend some time researching how it's done and why ashoat: By circumventing the `importJSON` framework that we use for all other imports, you're making… | |||||
const keys = JSON.parse(keysString); | |||||
pushApiPublicKey = keys.publicKey; | |||||
} catch { | |||||
ashoatUnsubmitted Not Done Inline ActionsShould we be printing some error? ashoat: Should we be printing some error? | |||||
return null; | |||||
} | |||||
return pushApiPublicKey; | |||||
} | |||||
let webpackCompiledRootComponent: ?React.ComponentType<{}> = null; | let webpackCompiledRootComponent: ?React.ComponentType<{}> = null; | ||||
async function getWebpackCompiledRootComponentForSSR() { | async function getWebpackCompiledRootComponentForSSR() { | ||||
if (webpackCompiledRootComponent) { | if (webpackCompiledRootComponent) { | ||||
return webpackCompiledRootComponent; | return webpackCompiledRootComponent; | ||||
} | } | ||||
try { | try { | ||||
// $FlowFixMe web/dist doesn't always exist | // $FlowFixMe web/dist doesn't always exist | ||||
const webpackBuild = await import('web/dist/app.build.cjs'); | const webpackBuild = await import('web/dist/app.build.cjs'); | ||||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | const navInfoPromise = (async () => { | ||||
return finalNavInfo; | return finalNavInfo; | ||||
})(); | })(); | ||||
const currentAsOfPromise = (async () => { | const currentAsOfPromise = (async () => { | ||||
const hasNotAcknowledgedPolicies = await hasNotAcknowledgedPoliciesPromise; | const hasNotAcknowledgedPolicies = await hasNotAcknowledgedPoliciesPromise; | ||||
return hasNotAcknowledgedPolicies ? 0 : initialTime; | return hasNotAcknowledgedPolicies ? 0 : initialTime; | ||||
})(); | })(); | ||||
const pushApiPublicKeyPromise = getPushApiPublicKey(); | |||||
const { jsURL, fontsURL, cssInclude } = await assetInfoPromise; | const { jsURL, fontsURL, cssInclude } = await assetInfoPromise; | ||||
// prettier-ignore | // prettier-ignore | ||||
res.write(html` | res.write(html` | ||||
<!DOCTYPE html> | <!DOCTYPE html> | ||||
<html lang="en"> | <html lang="en"> | ||||
<head> | <head> | ||||
<meta charset="utf-8" /> | <meta charset="utf-8" /> | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | const initialReduxState = await promiseAll({ | ||||
}, | }, | ||||
nextLocalID: 0, | nextLocalID: 0, | ||||
cookie: undefined, | cookie: undefined, | ||||
deviceToken: undefined, | deviceToken: undefined, | ||||
dataLoaded: viewer.loggedIn, | dataLoaded: viewer.loggedIn, | ||||
windowActive: true, | windowActive: true, | ||||
userPolicies: {}, | userPolicies: {}, | ||||
primaryIdentityPublicKey: null, | primaryIdentityPublicKey: null, | ||||
pushApiPublicKey: pushApiPublicKeyPromise, | |||||
_persist: null, | _persist: null, | ||||
}); | }); | ||||
const jsonStream = streamJSON(res, initialReduxState); | const jsonStream = streamJSON(res, initialReduxState); | ||||
await waitForStream(jsonStream); | await waitForStream(jsonStream); | ||||
res.end(html` | res.end(html` | ||||
; | ; | ||||
var baseURL = "${baseURL}"; | var baseURL = "${baseURL}"; | ||||
</script> | </script> | ||||
<script src="${jsURL}"></script> | <script src="${jsURL}"></script> | ||||
</body> | </body> | ||||
</html> | </html> | ||||
`); | `); | ||||
} | } | ||||
export { websiteResponder }; | export { websiteResponder }; |
It looks like we're introducing one use case right now where we need to open this file to access the publicKey parameter. Will we need to access other parameters in the future? Should this code be factored out into another file that can be used for accessing this config?