From d05001cb1345bd1d2de445951578676d76ef04e0 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 10 Nov 2020 15:50:23 -0600 Subject: [PATCH] Fetching site data first to get UserService / my_user. Fixes #66 --- src/server/index.tsx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/server/index.tsx b/src/server/index.tsx index 828fa0c6..e2d0c2ff 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 = (