Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/responders/website-responders.js
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
type AssetInfo = { | type AssetInfo = { | ||||
+jsURL: string, | +jsURL: string, | ||||
+fontsURL: string, | +fontsURL: string, | ||||
+cssInclude: string, | +cssInclude: string, | ||||
+olmFilename: string, | +olmFilename: string, | ||||
+sqljsFilename: string, | +sqljsFilename: string, | ||||
+opaqueURL: string, | |||||
}; | }; | ||||
let assetInfo: ?AssetInfo = null; | let assetInfo: ?AssetInfo = null; | ||||
async function getAssetInfo() { | async function getAssetInfo() { | ||||
if (assetInfo) { | if (assetInfo) { | ||||
return assetInfo; | return assetInfo; | ||||
} | } | ||||
if (process.env.NODE_ENV === 'development') { | if (process.env.NODE_ENV === 'development') { | ||||
const fontsURL = await getFontsURL(); | const fontsURL = await getFontsURL(); | ||||
assetInfo = { | assetInfo = { | ||||
jsURL: 'http://localhost:8080/dev.build.js', | jsURL: 'http://localhost:8080/dev.build.js', | ||||
fontsURL, | fontsURL, | ||||
cssInclude: '', | cssInclude: '', | ||||
olmFilename: '', | olmFilename: '', | ||||
sqljsFilename: '', | sqljsFilename: '', | ||||
opaqueURL: 'http://localhost:8080/opaque-ke.wasm', | |||||
}; | }; | ||||
return assetInfo; | return assetInfo; | ||||
} | } | ||||
try { | try { | ||||
const manifestString = await readFile('../web/dist/manifest.json', 'utf8'); | const manifestString = await readFile('../web/dist/manifest.json', 'utf8'); | ||||
const manifest = JSON.parse(manifestString); | const manifest = JSON.parse(manifestString); | ||||
const webworkersManifestString = await readFile( | const webworkersManifestString = await readFile( | ||||
'../web/dist/webworkers/manifest.json', | '../web/dist/webworkers/manifest.json', | ||||
'utf8', | 'utf8', | ||||
); | ); | ||||
const webworkersManifest = JSON.parse(webworkersManifestString); | const webworkersManifest = JSON.parse(webworkersManifestString); | ||||
assetInfo = { | assetInfo = { | ||||
jsURL: `compiled/${manifest['browser.js']}`, | jsURL: `compiled/${manifest['browser.js']}`, | ||||
fontsURL: googleFontsURL, | fontsURL: googleFontsURL, | ||||
cssInclude: html` | cssInclude: html` | ||||
<link | <link | ||||
rel="stylesheet" | rel="stylesheet" | ||||
type="text/css" | type="text/css" | ||||
href="compiled/${manifest['browser.css']}" | href="compiled/${manifest['browser.css']}" | ||||
/> | /> | ||||
`, | `, | ||||
olmFilename: manifest['olm.wasm'], | olmFilename: manifest['olm.wasm'], | ||||
sqljsFilename: webworkersManifest['sql-wasm.wasm'], | sqljsFilename: webworkersManifest['sql-wasm.wasm'], | ||||
opaqueURL: `compiled/${manifest['comm_opaque2_wasm_bg.wasm']}`, | |||||
}; | }; | ||||
return assetInfo; | return assetInfo; | ||||
} catch { | } catch { | ||||
throw new Error( | throw new Error( | ||||
'Could not load manifest.json for web build. ' + | 'Could not load manifest.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?', | ||||
); | ); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 209 Lines • ▼ Show 20 Lines | if (!pushConfig) { | ||||
if (process.env.NODE_ENV !== 'development') { | if (process.env.NODE_ENV !== 'development') { | ||||
console.warn('keyserver/secrets/web_push_config.json should exist'); | console.warn('keyserver/secrets/web_push_config.json should exist'); | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
return pushConfig.publicKey; | return pushConfig.publicKey; | ||||
})(); | })(); | ||||
const { jsURL, fontsURL, cssInclude, olmFilename, sqljsFilename } = | const { jsURL, fontsURL, cssInclude, olmFilename, sqljsFilename, opaqueURL } = | ||||
await assetInfoPromise; | 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 84 Lines • ▼ Show 20 Lines | ): Promise<void> { | ||||
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}"; | ||||
var olmFilename = "${olmFilename}"; | var olmFilename = "${olmFilename}"; | ||||
var sqljsFilename = "${sqljsFilename}"; | var sqljsFilename = "${sqljsFilename}"; | ||||
var opaqueURL = "${opaqueURL}"; | |||||
</script> | </script> | ||||
<script src="${jsURL}"></script> | <script src="${jsURL}"></script> | ||||
</body> | </body> | ||||
</html> | </html> | ||||
`); | `); | ||||
} | } | ||||
export { websiteResponder }; | export { websiteResponder }; |