Create sessions on boot requests instead of websocket handshakes
This commit is contained in:
parent
da87dccb53
commit
90785aba20
8 changed files with 141 additions and 188 deletions
|
@ -1,9 +1,6 @@
|
|||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
// This entrypoint gets inlined in the index page cached by service workers
|
||||
// and is responsible for fetching the data we would otherwise embed
|
||||
|
||||
window.__env__ = fetch('/data', {
|
||||
window.__init__ = fetch('/init', {
|
||||
credentials: 'same-origin'
|
||||
}).then(res => {
|
||||
if (res.ok) {
|
||||
|
|
|
@ -70,11 +70,8 @@ function loadState({ store }, env) {
|
|||
});
|
||||
}
|
||||
|
||||
export default function initialState(ctx) {
|
||||
if (window.__env__) {
|
||||
window.__env__.then(env => loadState(ctx, env));
|
||||
} else {
|
||||
const env = JSON.parse(document.getElementById('env').innerHTML);
|
||||
loadState(ctx, env);
|
||||
}
|
||||
export default async function initialState(ctx) {
|
||||
const env = await window.__init__;
|
||||
ctx.socket.connect();
|
||||
loadState(ctx, env);
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@ export default class Socket {
|
|||
});
|
||||
this.handlers = [];
|
||||
this.connected = false;
|
||||
|
||||
this.connect();
|
||||
}
|
||||
|
||||
connect() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue