Skip to content

Commit

Permalink
refactor: custom 404 page
Browse files Browse the repository at this point in the history
  • Loading branch information
nightnei committed Dec 16, 2021
1 parent f618320 commit fc92894
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
12 changes: 1 addition & 11 deletions src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { IlcIntl } from './IlcIntl';
import defaultIntlAdapter from './defaultIntlAdapter';
import { IIlcAppSdk } from './interfaces/IIlcAppSdk';
import { Render404 } from './interfaces/common';
import ResponseStatus from './interfaces/ResponseStatus';

export * from './types';
export * from './GlobalBrowserApi';
Expand Down Expand Up @@ -87,16 +86,7 @@ export default class IlcAppSdk implements IIlcAppSdk {
render404: Render404 = (isCustomPage) => {
// SSR
if (this.adapter.setStatus) {
const status: ResponseStatus = {
code: 404,
};

if (isCustomPage) {
status.headers = {
['X-ILC-Override']: 'error-page-content',
};
}
this.adapter.setStatus(status);
this.adapter.setStatus(404, isCustomPage);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/interfaces/ResponseStatus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type ResponseStatus = {
code?: number;
code: number;
headers?: Record<string, string>;
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/interfaces/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface AppSdkAdapter {
/** Unique application ID, if same app will be rendered twice on a page - it will get different IDs */
appId: string;
intl: IntlAdapter | null;
setStatus: (data: ResponseStatus) => void;
setStatus: (code: number, isCustomPage?: boolean) => void;
getStatus: () => ResponseStatus | undefined;
}

Expand Down
10 changes: 8 additions & 2 deletions src/server/IlcSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ export class IlcSdk {
getCurrentPathProps: () => passedProps,
appId,
intl: this.parseIntl(req),
setStatus: (status) => {
responseStatus = status;
setStatus: (code, isCustomPage) => {
responseStatus = { code };

if (isCustomPage) {
responseStatus.headers = {
['X-ILC-Override']: 'error-page-content',
};
}
},
getStatus: () => responseStatus,
};
Expand Down

0 comments on commit fc92894

Please sign in to comment.