Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/responders/website-responders.js
Show All 34 Lines | |||||
import { fetchEntryInfos } from '../fetchers/entry-fetchers.js'; | import { fetchEntryInfos } from '../fetchers/entry-fetchers.js'; | ||||
import { fetchMessageInfos } from '../fetchers/message-fetchers.js'; | import { fetchMessageInfos } from '../fetchers/message-fetchers.js'; | ||||
import { hasAnyNotAcknowledgedPolicies } from '../fetchers/policy-acknowledgment-fetchers.js'; | import { hasAnyNotAcknowledgedPolicies } from '../fetchers/policy-acknowledgment-fetchers.js'; | ||||
import { fetchThreadInfos } from '../fetchers/thread-fetchers.js'; | import { fetchThreadInfos } from '../fetchers/thread-fetchers.js'; | ||||
import { | import { | ||||
fetchCurrentUserInfo, | fetchCurrentUserInfo, | ||||
fetchKnownUserInfos, | fetchKnownUserInfos, | ||||
} from '../fetchers/user-fetchers.js'; | } from '../fetchers/user-fetchers.js'; | ||||
import { getWebPushConfig } from '../push/providers.js'; | |||||
import { setNewSession } from '../session/cookies.js'; | import { setNewSession } from '../session/cookies.js'; | ||||
import { Viewer } from '../session/viewer.js'; | import { Viewer } from '../session/viewer.js'; | ||||
import { streamJSON, waitForStream } from '../utils/json-stream.js'; | import { streamJSON, waitForStream } from '../utils/json-stream.js'; | ||||
import { getAppURLFactsFromRequestURL } from '../utils/urls.js'; | import { getAppURLFactsFromRequestURL } from '../utils/urls.js'; | ||||
const { renderToNodeStream } = ReactDOMServer; | const { renderToNodeStream } = ReactDOMServer; | ||||
const access = promisify(fs.access); | const access = promisify(fs.access); | ||||
▲ Show 20 Lines • Show All 248 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 = (async () => { | |||||
const pushConfig = await getWebPushConfig(); | |||||
if (!pushConfig) { | |||||
if (process.env.NODE_ENV !== 'development') { | |||||
console.warn('keyserver/secrets/web_push_config.json should exist'); | |||||
} | |||||
return null; | |||||
} | |||||
return pushConfig.publicKey; | |||||
})(); | |||||
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 }; |