Fetching site data first to get UserService / my_user. Fixes #66

This commit is contained in:
Dessalines 2020-11-10 15:50:23 -06:00
parent 2a4581e9ba
commit d05001cb13

View file

@ -10,7 +10,7 @@ import { IsoData } from '../shared/interfaces';
import { routes } from '../shared/routes'; import { routes } from '../shared/routes';
import IsomorphicCookie from 'isomorphic-cookie'; import IsomorphicCookie from 'isomorphic-cookie';
import { lemmyHttp, setAuth } from '../shared/utils'; import { lemmyHttp, setAuth } from '../shared/utils';
import { GetSiteForm, GetSiteResponse } from 'lemmy-js-client'; import { GetSiteForm } from 'lemmy-js-client';
import process from 'process'; import process from 'process';
import { Helmet } from 'inferno-helmet'; import { Helmet } from 'inferno-helmet';
import { initializeSite } from '../shared/initialize'; import { initializeSite } from '../shared/initialize';
@ -34,15 +34,15 @@ server.get('/*', async (req, res) => {
let promises: Promise<any>[] = []; let promises: Promise<any>[] = [];
let siteData = lemmyHttp.getSite(getSiteForm); // Get site data first
promises.push(siteData); let site = await lemmyHttp.getSite(getSiteForm);
initializeSite(site);
if (activeRoute.fetchInitialData) { if (activeRoute.fetchInitialData) {
promises.push(...activeRoute.fetchInitialData(auth, req.path)); promises.push(...activeRoute.fetchInitialData(auth, req.path));
} }
let resolver = await Promise.all(promises); let routeData = await Promise.all(promises);
let site: GetSiteResponse = resolver[0];
let routeData = resolver.slice(1, resolver.length);
// Redirect to the 404 if there's an API error // Redirect to the 404 if there's an API error
if (routeData[0] && routeData[0].error) { if (routeData[0] && routeData[0].error) {
@ -66,8 +66,6 @@ server.get('/*', async (req, res) => {
lang, lang,
}; };
initializeSite(site);
const wrapper = ( const wrapper = (
<StaticRouter location={req.url} context={isoData}> <StaticRouter location={req.url} context={isoData}>
<App site={isoData.site} /> <App site={isoData.site} />