@merkle-open/magnolia-headless-frontend-nextjs 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -76
- package/index.ts +1 -1
- package/package.json +61 -61
- package/src/Constants.ts +1 -1
- package/src/Dependencies.ts +14 -14
- package/src/Index.ts +8 -8
- package/src/api/ErrorPageApi.ts +30 -30
- package/src/api/RobotsTxtApi.ts +33 -33
- package/src/api/SitemapApi.ts +33 -33
- package/src/api/_Dependencies.ts +12 -12
- package/src/api/_Index.ts +3 -3
- package/src/api/_README.md +73 -73
- package/src/config/ComponentMappingsProvider.ts +5 -5
- package/src/config/ConfigProvider.ts +35 -35
- package/src/config/Logger.ts +10 -10
- package/src/config/StylesheetProvider.ts +3 -3
- package/src/config/_Index.ts +4 -4
- package/src/config/_README.md +115 -115
- package/src/dynamic-page/AbstractDynamicErrorPage.tsx +46 -45
- package/src/dynamic-page/AbstractDynamicPage.tsx +53 -53
- package/src/dynamic-page/DynamicErrorPage.tsx +55 -53
- package/src/dynamic-page/DynamicErrorPageGlobal.tsx +68 -66
- package/src/dynamic-page/DynamicPage.tsx +50 -50
- package/src/dynamic-page/DynamicPageLayout.tsx +35 -35
- package/src/dynamic-page/PageProps.ts +40 -40
- package/src/dynamic-page/_Dependencies.ts +16 -16
- package/src/dynamic-page/_Index.ts +5 -5
- package/src/helper/BasicAuth.ts +3 -3
- package/src/helper/BrowserLanguageProvider.ts +31 -31
- package/src/helper/Logger.ts +22 -22
- package/src/helper/MagnoliaContextProvider.ts +60 -60
- package/src/helper/MagnoliaPageRestClient.ts +80 -80
- package/src/helper/MetaProps.ts +23 -23
- package/src/helper/MetadataProvider.ts +54 -54
- package/src/helper/RestClient.ts +49 -49
- package/src/helper/_Dependencies.ts +18 -18
- package/src/helper/_Index.ts +2 -2
- package/src/middleware/Middleware.ts +61 -61
- package/src/middleware/_Dependencies.ts +14 -14
- package/src/middleware/_Index.ts +1 -1
- package/src/middleware/_README.md +72 -72
- package/src/middleware/impl/DynamicResponseHeaderMiddleware.ts +45 -45
- package/src/middleware/impl/I18nRedirectMiddleware.ts +29 -29
- package/src/middleware/impl/VanityMiddleware.ts +103 -103
- package/src/scripts/generate-magnolia-config.ts +55 -55
- package/src/templates/ComponentMappingsProvider.ts +17 -17
- package/src/templates/_Dependencies.ts +10 -8
- package/src/templates/_Index.ts +5 -5
- package/src/templates/_README.md +86 -86
- package/src/templates/areas/BaseProps.ts +5 -5
- package/src/templates/areas/__magnolia-editable-area/EditableArea.tsx +27 -27
- package/src/templates/areas/__magnolia-editable-area/EditableAreaProps.ts +12 -12
- package/src/templates/components/BaseProps.ts +3 -3
- package/src/templates/components/__magnolia-editable-component/EditableComponent.tsx +23 -23
- package/src/templates/components/__magnolia-editable-component/EditableComponentProps.ts +5 -5
- package/src/templates/components/_error/ErrorComponent.tsx +7 -7
- package/src/templates/components/_error/ErrorComponentProps.ts +4 -4
- package/src/templates/components/_error/template.json +4 -4
- package/src/templates/components/_redirect/RedirectComponent.tsx +17 -17
- package/src/templates/components/_redirect/RedirectComponentProps.ts +11 -11
- package/src/templates/components/_redirect/template.json +4 -4
- package/src/templates/elements/_error/ErrorBoundary.tsx +33 -33
- package/src/templates/elements/_error/ErrorElement.tsx +22 -22
- package/src/templates/elements/_error/ErrorElementProps.ts +6 -6
- package/src/templates/magnolia.config.ts +10 -10
- package/src/templates/pages/BaseProps.ts +4 -4
- package/src/templates/pages/__magnolia-editable-page/EditablePage.tsx +16 -16
- package/src/templates/pages/__magnolia-editable-page/EditablePageProps.ts +11 -11
- package/src/templates/pages/_error-static/ErrorStatic.tsx +31 -26
- package/src/templates/pages/_error-static/ErrorStaticProps.ts +6 -6
package/README.md
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
# Magnolia NextJs Headless Frontend
|
|
2
|
-
- [Templates](./src/templates/_README.md)
|
|
3
|
-
- [Proxy/Middleware](./src/middleware/_README.md)
|
|
4
|
-
- [Config](./src/config/_README.md)
|
|
5
|
-
- [API](./src/api/_README.md)
|
|
6
|
-
- [Dynamic-Page](./README_dynamic-page.md)
|
|
7
|
-
|
|
8
|
-
## setup
|
|
9
|
-
- Add the following dependencies to your package.json
|
|
10
|
-
- `@merkle-open/magnolia-headless-frontend-nextjs`
|
|
11
|
-
- [`tsyringe`](https://github.com/Microsoft/tsyringe)
|
|
12
|
-
- `reflect-metadata`
|
|
13
|
-
- `next`
|
|
14
|
-
- `react`
|
|
15
|
-
- `react-dom`
|
|
16
|
-
- Configure tsconfig.json to include the following settings (`./tsconfig.json`)
|
|
17
|
-
```json
|
|
18
|
-
{
|
|
19
|
-
"compilerOptions": {
|
|
20
|
-
"experimentalDecorators": true,
|
|
21
|
-
"emitDecoratorMetadata": true
|
|
22
|
-
},
|
|
23
|
-
"include": [
|
|
24
|
-
"node_modules/@merkle-open/magnolia-headless-frontend-nextjs"
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
- Configure the [middleware composer](./src/middleware/_README.md#configure-middleware-composer)
|
|
29
|
-
- Implement and bind the interfaces specified [here](./src/config/_README.md)
|
|
30
|
-
- Implement API endpoints specified [here](./src/api/_README.md)
|
|
31
|
-
- Configure [instrumentation.ts](https://nextjs.org/docs/app/guides/instrumentation#importing-files-with-side-effects) (`./instrumentation.ts`)
|
|
32
|
-
```typescript
|
|
33
|
-
export async function register() {
|
|
34
|
-
await import('reflect-metadata');
|
|
35
|
-
}
|
|
36
|
-
```
|
|
37
|
-
- Setup [dynamic page](./README_dynamic-page.md)
|
|
38
|
-
- Setup Dependencies (`./Dependencies.ts`)
|
|
39
|
-
```typescript
|
|
40
|
-
import 'reflect-metadata';
|
|
41
|
-
import { container } from 'tsyringe';
|
|
42
|
-
import { register as registerOss } from '@merkle-open/magnolia-headless-frontend-nextjs';
|
|
43
|
-
import registerConfigs from './config/_Dependencies.ts';
|
|
44
|
-
|
|
45
|
-
registerConfigs(container);
|
|
46
|
-
registerOss(container);
|
|
47
|
-
|
|
48
|
-
export { container };
|
|
49
|
-
```
|
|
50
|
-
- Setup next.config.ts (`./next.config.ts`)
|
|
51
|
-
```typescript
|
|
52
|
-
import type { NextConfig } from 'next';
|
|
53
|
-
import type { Rewrite } from 'next/dist/lib/load-custom-routes';
|
|
54
|
-
|
|
55
|
-
const nextConfig: NextConfig = {
|
|
56
|
-
transpilePackages: ['@merkle-open/magnolia-headless-frontend-nextjs'],
|
|
57
|
-
async rewrites(): Promise<Rewrite[]> {
|
|
58
|
-
return [
|
|
59
|
-
{
|
|
60
|
-
source: '/robots.txt',
|
|
61
|
-
destination: '/api/robots.txt',
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
source: '/:language([a-z]{2})/sitemap/:type',
|
|
65
|
-
destination: '/api/:language/sitemap/:type',
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
source: '/:language([a-z]{2})/:path*',
|
|
69
|
-
destination: '/dynamic/:language/:path*',
|
|
70
|
-
},
|
|
71
|
-
];
|
|
72
|
-
},
|
|
73
|
-
...
|
|
74
|
-
};
|
|
75
|
-
export default nextConfig;
|
|
76
|
-
```
|
|
1
|
+
# Magnolia NextJs Headless Frontend
|
|
2
|
+
- [Templates](./src/templates/_README.md)
|
|
3
|
+
- [Proxy/Middleware](./src/middleware/_README.md)
|
|
4
|
+
- [Config](./src/config/_README.md)
|
|
5
|
+
- [API](./src/api/_README.md)
|
|
6
|
+
- [Dynamic-Page](./README_dynamic-page.md)
|
|
7
|
+
|
|
8
|
+
## setup
|
|
9
|
+
- Add the following dependencies to your package.json
|
|
10
|
+
- `@merkle-open/magnolia-headless-frontend-nextjs`
|
|
11
|
+
- [`tsyringe`](https://github.com/Microsoft/tsyringe)
|
|
12
|
+
- `reflect-metadata`
|
|
13
|
+
- `next`
|
|
14
|
+
- `react`
|
|
15
|
+
- `react-dom`
|
|
16
|
+
- Configure tsconfig.json to include the following settings (`./tsconfig.json`)
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"compilerOptions": {
|
|
20
|
+
"experimentalDecorators": true,
|
|
21
|
+
"emitDecoratorMetadata": true
|
|
22
|
+
},
|
|
23
|
+
"include": [
|
|
24
|
+
"node_modules/@merkle-open/magnolia-headless-frontend-nextjs"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
- Configure the [middleware composer](./src/middleware/_README.md#configure-middleware-composer)
|
|
29
|
+
- Implement and bind the interfaces specified [here](./src/config/_README.md)
|
|
30
|
+
- Implement API endpoints specified [here](./src/api/_README.md)
|
|
31
|
+
- Configure [instrumentation.ts](https://nextjs.org/docs/app/guides/instrumentation#importing-files-with-side-effects) (`./instrumentation.ts`)
|
|
32
|
+
```typescript
|
|
33
|
+
export async function register() {
|
|
34
|
+
await import('reflect-metadata');
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
- Setup [dynamic page](./README_dynamic-page.md)
|
|
38
|
+
- Setup Dependencies (`./Dependencies.ts`)
|
|
39
|
+
```typescript
|
|
40
|
+
import 'reflect-metadata';
|
|
41
|
+
import { container } from 'tsyringe';
|
|
42
|
+
import { register as registerOss } from '@merkle-open/magnolia-headless-frontend-nextjs';
|
|
43
|
+
import registerConfigs from './config/_Dependencies.ts';
|
|
44
|
+
|
|
45
|
+
registerConfigs(container);
|
|
46
|
+
registerOss(container);
|
|
47
|
+
|
|
48
|
+
export { container };
|
|
49
|
+
```
|
|
50
|
+
- Setup next.config.ts (`./next.config.ts`)
|
|
51
|
+
```typescript
|
|
52
|
+
import type { NextConfig } from 'next';
|
|
53
|
+
import type { Rewrite } from 'next/dist/lib/load-custom-routes';
|
|
54
|
+
|
|
55
|
+
const nextConfig: NextConfig = {
|
|
56
|
+
transpilePackages: ['@merkle-open/magnolia-headless-frontend-nextjs'],
|
|
57
|
+
async rewrites(): Promise<Rewrite[]> {
|
|
58
|
+
return [
|
|
59
|
+
{
|
|
60
|
+
source: '/robots.txt',
|
|
61
|
+
destination: '/api/robots.txt',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
source: '/:language([a-z]{2})/sitemap/:type',
|
|
65
|
+
destination: '/api/:language/sitemap/:type',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
source: '/:language([a-z]{2})/:path*',
|
|
69
|
+
destination: '/dynamic/:language/:path*',
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
},
|
|
73
|
+
...
|
|
74
|
+
};
|
|
75
|
+
export default nextConfig;
|
|
76
|
+
```
|
package/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src/Index.ts';
|
|
1
|
+
export * from './src/Index.ts';
|
package/package.json
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@merkle-open/magnolia-headless-frontend-nextjs",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Magnolia headless frontend nextJs",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"author": "Merkle Inc.",
|
|
7
|
-
"private": false,
|
|
8
|
-
"main": "index.ts",
|
|
9
|
-
"module": "index.ts",
|
|
10
|
-
"type": "module",
|
|
11
|
-
"engines": {
|
|
12
|
-
"node": ">=24"
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"README.md",
|
|
16
|
-
"index.ts",
|
|
17
|
-
"src"
|
|
18
|
-
],
|
|
19
|
-
"repository": {
|
|
20
|
-
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/merkle-open/magnolia-headless.git"
|
|
22
|
-
},
|
|
23
|
-
"scripts": {
|
|
24
|
-
"generate-oss-magnoliaConfig": "npx tsx src/scripts/generate-magnolia-config.ts src/templates src/templates",
|
|
25
|
-
"build": "tsc --build",
|
|
26
|
-
"clean": "tsc --build --clean",
|
|
27
|
-
"format": "prettier --write src/**",
|
|
28
|
-
"lint": "eslint src/**",
|
|
29
|
-
"prepare": "cd .. && husky magnolia-headless-frontend-nextjs/.husky"
|
|
30
|
-
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@magnolia/react-editor": "2.1.1"
|
|
33
|
-
},
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"next": "^16.1",
|
|
36
|
-
"react": "^19.2",
|
|
37
|
-
"react-dom": "^19.2",
|
|
38
|
-
"reflect-metadata": "^0.2",
|
|
39
|
-
"tsyringe": "^4.4"
|
|
40
|
-
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"@eslint/js": "^9.39.3",
|
|
43
|
-
"@types/node": "^25.0.10",
|
|
44
|
-
"@types/react": "19.2.10",
|
|
45
|
-
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
46
|
-
"@typescript-eslint/parser": "^8.56.1",
|
|
47
|
-
"eslint": "^9.39.3",
|
|
48
|
-
"eslint-config-prettier": "^10.1.8",
|
|
49
|
-
"eslint-plugin-prettier": "^5.5.5",
|
|
50
|
-
"eslint-plugin-react": "^7.37.5",
|
|
51
|
-
"husky": "^9.1.7",
|
|
52
|
-
"lint-staged": "^16.2.7",
|
|
53
|
-
"prettier": "^3.8.1",
|
|
54
|
-
"tsx": "^4.21.0",
|
|
55
|
-
"typescript-eslint": "^8.56.1",
|
|
56
|
-
"jiti": "^2.6.1"
|
|
57
|
-
},
|
|
58
|
-
"lint-staged": {
|
|
59
|
-
"*.{js,jsx,ts,tsx,md,mdx,html,css}": "npm run format"
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@merkle-open/magnolia-headless-frontend-nextjs",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Magnolia headless frontend nextJs",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Merkle Inc.",
|
|
7
|
+
"private": false,
|
|
8
|
+
"main": "index.ts",
|
|
9
|
+
"module": "index.ts",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=24"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"README.md",
|
|
16
|
+
"index.ts",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/merkle-open/magnolia-headless.git"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"generate-oss-magnoliaConfig": "npx tsx src/scripts/generate-magnolia-config.ts src/templates src/templates",
|
|
25
|
+
"build": "tsc --build",
|
|
26
|
+
"clean": "tsc --build --clean",
|
|
27
|
+
"format": "prettier --write src/**",
|
|
28
|
+
"lint": "eslint src/**",
|
|
29
|
+
"prepare": "cd .. && husky magnolia-headless-frontend-nextjs/.husky"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@magnolia/react-editor": "2.1.1"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"next": "^16.1",
|
|
36
|
+
"react": "^19.2",
|
|
37
|
+
"react-dom": "^19.2",
|
|
38
|
+
"reflect-metadata": "^0.2",
|
|
39
|
+
"tsyringe": "^4.4"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@eslint/js": "^9.39.3",
|
|
43
|
+
"@types/node": "^25.0.10",
|
|
44
|
+
"@types/react": "19.2.10",
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
46
|
+
"@typescript-eslint/parser": "^8.56.1",
|
|
47
|
+
"eslint": "^9.39.3",
|
|
48
|
+
"eslint-config-prettier": "^10.1.8",
|
|
49
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
50
|
+
"eslint-plugin-react": "^7.37.5",
|
|
51
|
+
"husky": "^9.1.7",
|
|
52
|
+
"lint-staged": "^16.2.7",
|
|
53
|
+
"prettier": "^3.8.1",
|
|
54
|
+
"tsx": "^4.21.0",
|
|
55
|
+
"typescript-eslint": "^8.56.1",
|
|
56
|
+
"jiti": "^2.6.1"
|
|
57
|
+
},
|
|
58
|
+
"lint-staged": {
|
|
59
|
+
"*.{js,jsx,ts,tsx,md,mdx,html,css}": "npm run format"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/Constants.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const TOKEN_PREFIX = 'com.merkle.oss.magnolia.headless.';
|
|
1
|
+
export const TOKEN_PREFIX = 'com.merkle.oss.magnolia.headless.';
|
package/src/Dependencies.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { DependencyContainer } from 'tsyringe';
|
|
2
|
-
import registerApis from './api/_Dependencies.ts';
|
|
3
|
-
import registerDynamicPages from './dynamic-page/_Dependencies.ts';
|
|
4
|
-
import registerHelpers from './helper/_Dependencies.ts';
|
|
5
|
-
import registerMiddlewares from './middleware/_Dependencies.ts';
|
|
6
|
-
import registerTemplates from './templates/_Dependencies.ts';
|
|
7
|
-
|
|
8
|
-
export function register(container: DependencyContainer) {
|
|
9
|
-
registerApis(container);
|
|
10
|
-
registerDynamicPages(container);
|
|
11
|
-
registerHelpers(container);
|
|
12
|
-
registerMiddlewares(container);
|
|
13
|
-
registerTemplates(container);
|
|
14
|
-
}
|
|
1
|
+
import { DependencyContainer } from 'tsyringe';
|
|
2
|
+
import registerApis from './api/_Dependencies.ts';
|
|
3
|
+
import registerDynamicPages from './dynamic-page/_Dependencies.ts';
|
|
4
|
+
import registerHelpers from './helper/_Dependencies.ts';
|
|
5
|
+
import registerMiddlewares from './middleware/_Dependencies.ts';
|
|
6
|
+
import registerTemplates from './templates/_Dependencies.ts';
|
|
7
|
+
|
|
8
|
+
export function register(container: DependencyContainer) {
|
|
9
|
+
registerApis(container);
|
|
10
|
+
registerDynamicPages(container);
|
|
11
|
+
registerHelpers(container);
|
|
12
|
+
registerMiddlewares(container);
|
|
13
|
+
registerTemplates(container);
|
|
14
|
+
}
|
package/src/Index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './api/_Index.ts';
|
|
2
|
-
export * from './dynamic-page/_Index.ts';
|
|
3
|
-
export * from './config/_Index.ts';
|
|
4
|
-
export * from './helper/_Index.ts';
|
|
5
|
-
export * from './middleware/_Index.ts';
|
|
6
|
-
export * from './templates/_Index.ts';
|
|
7
|
-
export * from './Constants.ts';
|
|
8
|
-
export * from './Dependencies.ts';
|
|
1
|
+
export * from './api/_Index.ts';
|
|
2
|
+
export * from './dynamic-page/_Index.ts';
|
|
3
|
+
export * from './config/_Index.ts';
|
|
4
|
+
export * from './helper/_Index.ts';
|
|
5
|
+
export * from './middleware/_Index.ts';
|
|
6
|
+
export * from './templates/_Index.ts';
|
|
7
|
+
export * from './Constants.ts';
|
|
8
|
+
export * from './Dependencies.ts';
|
package/src/api/ErrorPageApi.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { NextRequest } from 'next/server';
|
|
2
|
-
import { inject, injectable } from 'tsyringe';
|
|
3
|
-
import { ErrorType, MagnoliaPageRestClient } from '../helper/MagnoliaPageRestClient.ts';
|
|
4
|
-
|
|
5
|
-
import { TOKEN_PREFIX } from '../Constants.ts';
|
|
6
|
-
|
|
7
|
-
@injectable()
|
|
8
|
-
export class ErrorPageApi {
|
|
9
|
-
constructor(@inject(TOKEN_PREFIX + 'MagnoliaPageRestClient') private magnoliaPageRestClient: MagnoliaPageRestClient) {}
|
|
10
|
-
|
|
11
|
-
public async get(req: NextRequest, language: string): Promise<Response> {
|
|
12
|
-
const queryParams = req.nextUrl.searchParams;
|
|
13
|
-
const url = new URL(`https://${req.headers.get('host')}/${language}`);
|
|
14
|
-
const errorType = this.getErrorTypeFromString(queryParams.get('errorType'));
|
|
15
|
-
const headers = new Headers();
|
|
16
|
-
headers.set('Content-Type', 'application/json');
|
|
17
|
-
return this.magnoliaPageRestClient
|
|
18
|
-
.getErrorPageContent(url, errorType)
|
|
19
|
-
.then((content) => JSON.stringify(content))
|
|
20
|
-
.then((body) => new Response(body, { headers: headers }));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
private getErrorTypeFromString(value: string): ErrorType | undefined {
|
|
24
|
-
const directions = Object.values(ErrorType);
|
|
25
|
-
if (directions.includes(value as ErrorType)) {
|
|
26
|
-
return value as ErrorType;
|
|
27
|
-
}
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
import { inject, injectable } from 'tsyringe';
|
|
3
|
+
import { ErrorType, MagnoliaPageRestClient } from '../helper/MagnoliaPageRestClient.ts';
|
|
4
|
+
|
|
5
|
+
import { TOKEN_PREFIX } from '../Constants.ts';
|
|
6
|
+
|
|
7
|
+
@injectable()
|
|
8
|
+
export class ErrorPageApi {
|
|
9
|
+
constructor(@inject(TOKEN_PREFIX + 'MagnoliaPageRestClient') private magnoliaPageRestClient: MagnoliaPageRestClient) {}
|
|
10
|
+
|
|
11
|
+
public async get(req: NextRequest, language: string): Promise<Response> {
|
|
12
|
+
const queryParams = req.nextUrl.searchParams;
|
|
13
|
+
const url = new URL(`https://${req.headers.get('host')}/${language}`);
|
|
14
|
+
const errorType = this.getErrorTypeFromString(queryParams.get('errorType'));
|
|
15
|
+
const headers = new Headers();
|
|
16
|
+
headers.set('Content-Type', 'application/json');
|
|
17
|
+
return this.magnoliaPageRestClient
|
|
18
|
+
.getErrorPageContent(url, errorType)
|
|
19
|
+
.then((content) => JSON.stringify(content))
|
|
20
|
+
.then((body) => new Response(body, { headers: headers }));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private getErrorTypeFromString(value: string): ErrorType | undefined {
|
|
24
|
+
const directions = Object.values(ErrorType);
|
|
25
|
+
if (directions.includes(value as ErrorType)) {
|
|
26
|
+
return value as ErrorType;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/api/RobotsTxtApi.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { RestClient } from '../helper/RestClient.ts';
|
|
2
|
-
import { NextRequest } from 'next/server';
|
|
3
|
-
import { inject, injectable } from 'tsyringe';
|
|
4
|
-
import type { HeadlessConfigProviderI, MagnoliaApiEndpointsProvider } from '../config/ConfigProvider.ts';
|
|
5
|
-
|
|
6
|
-
import { TOKEN_PREFIX } from '../Constants.ts';
|
|
7
|
-
|
|
8
|
-
@injectable()
|
|
9
|
-
export class RobotsTxtApi {
|
|
10
|
-
private readonly apisProvider: MagnoliaApiEndpointsProvider;
|
|
11
|
-
|
|
12
|
-
constructor(
|
|
13
|
-
@inject(TOKEN_PREFIX + 'HeadlessConfigProviderI') configProvider: HeadlessConfigProviderI,
|
|
14
|
-
@inject(TOKEN_PREFIX + 'RestClient') private restClient: RestClient,
|
|
15
|
-
) {
|
|
16
|
-
this.apisProvider = configProvider.get().magnoliaApisProvider;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public async get(req: NextRequest, sitemapUrlTemplate: string): Promise<Response> {
|
|
20
|
-
const domain: string = new URL('https://' + req.headers.get('host')).hostname; //strip port
|
|
21
|
-
const headers = new Headers();
|
|
22
|
-
headers.set('Content-Type', 'text/plain');
|
|
23
|
-
return this.getRobots(domain, sitemapUrlTemplate).then((robots) => new Response(robots, { headers: headers }));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
private async getRobots(domain: string, sitemapUrlTemplate: string): Promise<string> {
|
|
27
|
-
const queryParams = new URLSearchParams();
|
|
28
|
-
queryParams.set('domain', domain);
|
|
29
|
-
queryParams.set('sitemapUrlTemplate', sitemapUrlTemplate);
|
|
30
|
-
const url = this.apisProvider.robots() + '?' + queryParams.toString();
|
|
31
|
-
return this.restClient.fetchMagnoliaBasicAuth(url).then((response) => this.restClient.getText(url, response));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
import { RestClient } from '../helper/RestClient.ts';
|
|
2
|
+
import { NextRequest } from 'next/server';
|
|
3
|
+
import { inject, injectable } from 'tsyringe';
|
|
4
|
+
import type { HeadlessConfigProviderI, MagnoliaApiEndpointsProvider } from '../config/ConfigProvider.ts';
|
|
5
|
+
|
|
6
|
+
import { TOKEN_PREFIX } from '../Constants.ts';
|
|
7
|
+
|
|
8
|
+
@injectable()
|
|
9
|
+
export class RobotsTxtApi {
|
|
10
|
+
private readonly apisProvider: MagnoliaApiEndpointsProvider;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
@inject(TOKEN_PREFIX + 'HeadlessConfigProviderI') configProvider: HeadlessConfigProviderI,
|
|
14
|
+
@inject(TOKEN_PREFIX + 'RestClient') private restClient: RestClient,
|
|
15
|
+
) {
|
|
16
|
+
this.apisProvider = configProvider.get().magnoliaApisProvider;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public async get(req: NextRequest, sitemapUrlTemplate: string): Promise<Response> {
|
|
20
|
+
const domain: string = new URL('https://' + req.headers.get('host')).hostname; //strip port
|
|
21
|
+
const headers = new Headers();
|
|
22
|
+
headers.set('Content-Type', 'text/plain');
|
|
23
|
+
return this.getRobots(domain, sitemapUrlTemplate).then((robots) => new Response(robots, { headers: headers }));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private async getRobots(domain: string, sitemapUrlTemplate: string): Promise<string> {
|
|
27
|
+
const queryParams = new URLSearchParams();
|
|
28
|
+
queryParams.set('domain', domain);
|
|
29
|
+
queryParams.set('sitemapUrlTemplate', sitemapUrlTemplate);
|
|
30
|
+
const url = this.apisProvider.robots() + '?' + queryParams.toString();
|
|
31
|
+
return this.restClient.fetchMagnoliaBasicAuth(url).then((response) => this.restClient.getText(url, response));
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/api/SitemapApi.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { RestClient } from '../helper/RestClient.ts';
|
|
2
|
-
import { NextRequest } from 'next/server';
|
|
3
|
-
import { inject, injectable } from 'tsyringe';
|
|
4
|
-
import type { HeadlessConfigProviderI, MagnoliaApiEndpointsProvider } from '../config/ConfigProvider.ts';
|
|
5
|
-
|
|
6
|
-
import { TOKEN_PREFIX } from '../Constants.ts';
|
|
7
|
-
|
|
8
|
-
@injectable()
|
|
9
|
-
export class SitemapApi {
|
|
10
|
-
private readonly apisProvider: MagnoliaApiEndpointsProvider;
|
|
11
|
-
|
|
12
|
-
constructor(
|
|
13
|
-
@inject(TOKEN_PREFIX + 'HeadlessConfigProviderI') configProvider: HeadlessConfigProviderI,
|
|
14
|
-
@inject(TOKEN_PREFIX + 'RestClient') private restClient: RestClient,
|
|
15
|
-
) {
|
|
16
|
-
this.apisProvider = configProvider.get().magnoliaApisProvider;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public async get(req: NextRequest, language: string, type: string): Promise<Response> {
|
|
20
|
-
const domain: string = new URL('https://' + req.headers.get('host')).hostname; //strip port
|
|
21
|
-
const headers = new Headers();
|
|
22
|
-
headers.set('Content-Type', 'application/xml');
|
|
23
|
-
return this.getSitemap(domain, language, type).then((sitemap) => new Response(sitemap, { headers: headers }));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
private async getSitemap(domain: string, language: string, type: string): Promise<string> {
|
|
27
|
-
const queryParams = new URLSearchParams();
|
|
28
|
-
queryParams.set('domain', domain);
|
|
29
|
-
queryParams.set('type', type);
|
|
30
|
-
const url = this.apisProvider.sitemap(language) + '?' + queryParams.toString();
|
|
31
|
-
return this.restClient.fetchMagnoliaBasicAuth(url).then((response) => this.restClient.getText(url, response, 'application/xml'));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
import { RestClient } from '../helper/RestClient.ts';
|
|
2
|
+
import { NextRequest } from 'next/server';
|
|
3
|
+
import { inject, injectable } from 'tsyringe';
|
|
4
|
+
import type { HeadlessConfigProviderI, MagnoliaApiEndpointsProvider } from '../config/ConfigProvider.ts';
|
|
5
|
+
|
|
6
|
+
import { TOKEN_PREFIX } from '../Constants.ts';
|
|
7
|
+
|
|
8
|
+
@injectable()
|
|
9
|
+
export class SitemapApi {
|
|
10
|
+
private readonly apisProvider: MagnoliaApiEndpointsProvider;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
@inject(TOKEN_PREFIX + 'HeadlessConfigProviderI') configProvider: HeadlessConfigProviderI,
|
|
14
|
+
@inject(TOKEN_PREFIX + 'RestClient') private restClient: RestClient,
|
|
15
|
+
) {
|
|
16
|
+
this.apisProvider = configProvider.get().magnoliaApisProvider;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public async get(req: NextRequest, language: string, type: string): Promise<Response> {
|
|
20
|
+
const domain: string = new URL('https://' + req.headers.get('host')).hostname; //strip port
|
|
21
|
+
const headers = new Headers();
|
|
22
|
+
headers.set('Content-Type', 'application/xml');
|
|
23
|
+
return this.getSitemap(domain, language, type).then((sitemap) => new Response(sitemap, { headers: headers }));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private async getSitemap(domain: string, language: string, type: string): Promise<string> {
|
|
27
|
+
const queryParams = new URLSearchParams();
|
|
28
|
+
queryParams.set('domain', domain);
|
|
29
|
+
queryParams.set('type', type);
|
|
30
|
+
const url = this.apisProvider.sitemap(language) + '?' + queryParams.toString();
|
|
31
|
+
return this.restClient.fetchMagnoliaBasicAuth(url).then((response) => this.restClient.getText(url, response, 'application/xml'));
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/api/_Dependencies.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { DependencyContainer } from 'tsyringe';
|
|
2
|
-
import { ErrorPageApi } from './ErrorPageApi.ts';
|
|
3
|
-
import { RobotsTxtApi } from './RobotsTxtApi.ts';
|
|
4
|
-
import { SitemapApi } from './SitemapApi.ts';
|
|
5
|
-
|
|
6
|
-
import { TOKEN_PREFIX } from '../Constants.ts';
|
|
7
|
-
|
|
8
|
-
export default function register(container: DependencyContainer) {
|
|
9
|
-
container.register(TOKEN_PREFIX + 'ErrorPageApi', { useClass: ErrorPageApi });
|
|
10
|
-
container.register(TOKEN_PREFIX + 'RobotsTxtApi', { useClass: RobotsTxtApi });
|
|
11
|
-
container.register(TOKEN_PREFIX + 'SitemapApi', { useClass: SitemapApi });
|
|
12
|
-
}
|
|
1
|
+
import { DependencyContainer } from 'tsyringe';
|
|
2
|
+
import { ErrorPageApi } from './ErrorPageApi.ts';
|
|
3
|
+
import { RobotsTxtApi } from './RobotsTxtApi.ts';
|
|
4
|
+
import { SitemapApi } from './SitemapApi.ts';
|
|
5
|
+
|
|
6
|
+
import { TOKEN_PREFIX } from '../Constants.ts';
|
|
7
|
+
|
|
8
|
+
export default function register(container: DependencyContainer) {
|
|
9
|
+
container.register(TOKEN_PREFIX + 'ErrorPageApi', { useClass: ErrorPageApi });
|
|
10
|
+
container.register(TOKEN_PREFIX + 'RobotsTxtApi', { useClass: RobotsTxtApi });
|
|
11
|
+
container.register(TOKEN_PREFIX + 'SitemapApi', { useClass: SitemapApi });
|
|
12
|
+
}
|
package/src/api/_Index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './ErrorPageApi.ts';
|
|
2
|
-
export * from './RobotsTxtApi.ts';
|
|
3
|
-
export * from './SitemapApi.ts';
|
|
1
|
+
export * from './ErrorPageApi.ts';
|
|
2
|
+
export * from './RobotsTxtApi.ts';
|
|
3
|
+
export * from './SitemapApi.ts';
|