mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-29 15:51:14 +00:00
fix merge conflicts
This commit is contained in:
parent
e6005daadf
commit
96abf25d00
1 changed files with 16 additions and 15 deletions
|
@ -8,9 +8,13 @@ import { getHttpBaseInternal } from "../../shared/env";
|
||||||
import {
|
import {
|
||||||
InitialFetchRequest,
|
InitialFetchRequest,
|
||||||
IsoDataOptionalSite,
|
IsoDataOptionalSite,
|
||||||
|
RouteData,
|
||||||
} from "../../shared/interfaces";
|
} from "../../shared/interfaces";
|
||||||
import { routes } from "../../shared/routes";
|
import { routes } from "../../shared/routes";
|
||||||
import { RequestState, wrapClient } from "../../shared/services/HttpService";
|
import {
|
||||||
|
FailedRequestState,
|
||||||
|
wrapClient,
|
||||||
|
} from "../../shared/services/HttpService";
|
||||||
import { ErrorPageData, initializeSite, isAuthPath } from "../../shared/utils";
|
import { ErrorPageData, initializeSite, isAuthPath } from "../../shared/utils";
|
||||||
import { createSsrHtml } from "../utils/create-ssr-html";
|
import { createSsrHtml } from "../utils/create-ssr-html";
|
||||||
import { getErrorPageData } from "../utils/get-error-page-data";
|
import { getErrorPageData } from "../utils/get-error-page-data";
|
||||||
|
@ -32,7 +36,7 @@ export default async (req: Request, res: Response) => {
|
||||||
// This bypasses errors, so that the client can hit the error on its own,
|
// This bypasses errors, so that the client can hit the error on its own,
|
||||||
// in order to remove the jwt on the browser. Necessary for wrong jwts
|
// in order to remove the jwt on the browser. Necessary for wrong jwts
|
||||||
let site: GetSiteResponse | undefined = undefined;
|
let site: GetSiteResponse | undefined = undefined;
|
||||||
const routeData: RequestState<any>[] = [];
|
let routeData: RouteData = {};
|
||||||
let errorPageData: ErrorPageData | undefined = undefined;
|
let errorPageData: ErrorPageData | undefined = undefined;
|
||||||
let try_site = await client.getSite(getSiteForm);
|
let try_site = await client.getSite(getSiteForm);
|
||||||
if (try_site.state === "failed" && try_site.msg == "not_logged_in") {
|
if (try_site.state === "failed" && try_site.msg == "not_logged_in") {
|
||||||
|
@ -56,7 +60,7 @@ export default async (req: Request, res: Response) => {
|
||||||
return res.redirect("/setup");
|
return res.redirect("/setup");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (site) {
|
if (site && activeRoute?.fetchInitialData) {
|
||||||
const initialFetchReq: InitialFetchRequest = {
|
const initialFetchReq: InitialFetchRequest = {
|
||||||
client,
|
client,
|
||||||
auth,
|
auth,
|
||||||
|
@ -65,26 +69,23 @@ export default async (req: Request, res: Response) => {
|
||||||
site,
|
site,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (activeRoute?.fetchInitialData) {
|
routeData = await activeRoute.fetchInitialData(initialFetchReq);
|
||||||
routeData.push(
|
|
||||||
...(await Promise.all([
|
|
||||||
...activeRoute.fetchInitialData(initialFetchReq),
|
|
||||||
]))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (try_site.state === "failed") {
|
} else if (try_site.state === "failed") {
|
||||||
errorPageData = getErrorPageData(new Error(try_site.msg), site);
|
errorPageData = getErrorPageData(new Error(try_site.msg), site);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const error = Object.values(routeData).find(
|
||||||
|
res => res.state === "failed"
|
||||||
|
) as FailedRequestState | undefined;
|
||||||
|
|
||||||
// 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].state === "failed") {
|
if (error) {
|
||||||
const error = routeData[0].msg;
|
console.error(error.msg);
|
||||||
console.error(error);
|
if (error.msg === "instance_is_private") {
|
||||||
if (error === "instance_is_private") {
|
|
||||||
return res.redirect(`/signup`);
|
return res.redirect(`/signup`);
|
||||||
} else {
|
} else {
|
||||||
errorPageData = getErrorPageData(new Error(error), site);
|
errorPageData = getErrorPageData(new Error(error.msg), site);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue