From: Dessalines Date: Tue, 10 Nov 2020 21:50:23 +0000 (-0600) Subject: Fetching site data first to get UserService / my_user. Fixes #66 X-Git-Url: http://these/git/%7BallRss%7D?a=commitdiff_plain;h=d05001cb1345bd1d2de445951578676d76ef04e0;p=lemmy-ui.git Fetching site data first to get UserService / my_user. Fixes #66 --- diff --git a/src/server/index.tsx b/src/server/index.tsx index 828fa0c..e2d0c2f 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -10,7 +10,7 @@ import { IsoData } from '../shared/interfaces'; import { routes } from '../shared/routes'; import IsomorphicCookie from 'isomorphic-cookie'; import { lemmyHttp, setAuth } from '../shared/utils'; -import { GetSiteForm, GetSiteResponse } from 'lemmy-js-client'; +import { GetSiteForm } from 'lemmy-js-client'; import process from 'process'; import { Helmet } from 'inferno-helmet'; import { initializeSite } from '../shared/initialize'; @@ -34,15 +34,15 @@ server.get('/*', async (req, res) => { let promises: Promise[] = []; - let siteData = lemmyHttp.getSite(getSiteForm); - promises.push(siteData); + // Get site data first + let site = await lemmyHttp.getSite(getSiteForm); + initializeSite(site); + if (activeRoute.fetchInitialData) { promises.push(...activeRoute.fetchInitialData(auth, req.path)); } - let resolver = await Promise.all(promises); - let site: GetSiteResponse = resolver[0]; - let routeData = resolver.slice(1, resolver.length); + let routeData = await Promise.all(promises); // Redirect to the 404 if there's an API error if (routeData[0] && routeData[0].error) { @@ -66,8 +66,6 @@ server.get('/*', async (req, res) => { lang, }; - initializeSite(site); - const wrapper = (