create-content-sdk-app 2.3.0 → 2.4.0-canary.20260720140034
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.
|
@@ -10,7 +10,6 @@ The functionality available in Content SDK Angular right now includes:
|
|
|
10
10
|
|
|
11
11
|
What can you expect coming in the future ahead of the 1.0 release:
|
|
12
12
|
- SXA Redirects support
|
|
13
|
-
- More varied hosting options
|
|
14
13
|
- Ongoing optimizations and bug fixes
|
|
15
14
|
|
|
16
15
|
## Deployment
|
|
@@ -32,10 +31,126 @@ But, temporarily, we ask you to perform some additional actions post-deploy in y
|
|
|
32
31
|
|
|
33
32
|
These variables are needed to ensure SAI backend infrastructure correctly sets up and uses your Angular sample for Pages editing and preview. They will be switched to be set automatically between now and the 1.0 release.
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
## Non-Sitecore AI deployments
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
For both deploying to Netlify and Vercel, ensure your `src/server.ts` file has the default export for the request handler:
|
|
37
|
+
```
|
|
38
|
+
export default reqHandler;
|
|
39
|
+
```
|
|
38
40
|
|
|
39
41
|
### Deploying to Vercel
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
Content SDK for Angular sample uses ExpressJS extensively to enhance the base Angular capabilities with Sitecore AI features.
|
|
44
|
+
Since Express is being used, and since Vercel has no Angular SSR support, you need to create a Vercel function file in order for Vercel to correctly serve the application.
|
|
45
|
+
For example, create a `vercel/index.mjs` file and import the Angular's compiled `server.mjs`output:
|
|
46
|
+
```
|
|
47
|
+
export { default } from '../dist/<your_app_name>/server/server.mjs';
|
|
48
|
+
```
|
|
49
|
+
where `<your_app_name>` is the name of application set in `package.json`.
|
|
50
|
+
|
|
51
|
+
After that, configure redirect rules for Vercel request to reach your app code, via `vercel.json` file:
|
|
52
|
+
```
|
|
53
|
+
{
|
|
54
|
+
"$schema": "https://openapi.vercel.sh/vercel.json",
|
|
55
|
+
"buildCommand": "npm run build",
|
|
56
|
+
"outputDirectory": "dist/<your_app_name>/browser",
|
|
57
|
+
"rewrites": [
|
|
58
|
+
{
|
|
59
|
+
"source": "/(.*)",
|
|
60
|
+
"destination": "/vercel/index"
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"functions": {
|
|
64
|
+
"vercel/index.mjs": {
|
|
65
|
+
"includeFiles": "dist/<your_app_name>/**"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
3. In Vercel portal, set the required Content SDK environment variables. Additionally, set `NG_ALLOWED_HOSTS` environment variable to allow Vercel URLs:
|
|
72
|
+
```
|
|
73
|
+
NG_ALLOWED_HOSTS=*.vercel.app`
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Deploying your app to Vercel should now result in the site being correctly served.
|
|
77
|
+
|
|
78
|
+
### Deploying to Netlify
|
|
79
|
+
|
|
80
|
+
As ExpressJS is being used by Content SDK for Angular, the natural instinct would be to follow the [express guide from Netlify](https://docs.netlify.com/build/frameworks/framework-setup-guides/express/#deploy-your-express-app-with-netlify-cli)
|
|
81
|
+
Unfortunately, this will result in your Netlify functions being compiled as CJS and some built in functionality of Angular (like `import.meta` values) being unavailable.
|
|
82
|
+
In order to build the function with Netlify's latest v2 API and have it compiled as ESM, some hoop jumps are required, using the express deployment guide as basis.
|
|
83
|
+
|
|
84
|
+
1. `serverless-http` module provides the required bridge between Express and Netlify, so you should install it alongside few additional dependencies that your Netlify function will use:
|
|
85
|
+
```
|
|
86
|
+
npm i express serverless-http @netlify/functions @types/express
|
|
87
|
+
```
|
|
88
|
+
2. Create a function implementation file that will import Angular's SSR artifacts and transform them to be used by `serverless-http` and v2 functions. These transformations are needed for Netlify CLI to correctly identify the function as ESM-compatible. The below example is for a TypeScript implementaion. We assume this function is located in the `netlify/functions/server.mts` file:
|
|
89
|
+
```
|
|
90
|
+
import serverless from 'serverless-http';
|
|
91
|
+
import type { Context } from '@netlify/functions';
|
|
92
|
+
import { default as app } from '../../dist/<your_app_name>/server/server.mjs';
|
|
93
|
+
|
|
94
|
+
const handler = serverless(app);
|
|
95
|
+
const FUNCTION_BASE = '/.netlify/functions/server';
|
|
96
|
+
|
|
97
|
+
/** serverless-http's result for a Lambda Function URL ("2.0") event. */
|
|
98
|
+
interface LambdaResult {
|
|
99
|
+
statusCode: number;
|
|
100
|
+
headers: Record<string, string>;
|
|
101
|
+
cookies: string[];
|
|
102
|
+
body: string;
|
|
103
|
+
isBase64Encoded: boolean;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default async (request: Request, context: Context) => {
|
|
107
|
+
const url = new URL(request.url);
|
|
108
|
+
// The netlify.toml rewrite passes the original path; direct invocations
|
|
109
|
+
// arrive prefixed with the function base path — strip it.
|
|
110
|
+
const path = url.pathname.startsWith(FUNCTION_BASE)
|
|
111
|
+
? url.pathname.slice(FUNCTION_BASE.length) || '/'
|
|
112
|
+
: url.pathname;
|
|
113
|
+
|
|
114
|
+
// Lambda Function URL ("2.0") event — the leanest shape serverless-http accepts
|
|
115
|
+
const lambdaRequest = {
|
|
116
|
+
version: '2.0',
|
|
117
|
+
rawPath: path,
|
|
118
|
+
rawQueryString: url.searchParams.toString(),
|
|
119
|
+
headers: Object.fromEntries(request.headers),
|
|
120
|
+
requestContext: { http: { method: request.method } },
|
|
121
|
+
body: Buffer.from(await request.arrayBuffer()),
|
|
122
|
+
};
|
|
123
|
+
const result = (await handler(lambdaRequest, context)) as LambdaResult;
|
|
124
|
+
|
|
125
|
+
// set-cookie comes back separately; `|| null` keeps 204/304 responses body-less.
|
|
126
|
+
const headers = new Headers(result.headers);
|
|
127
|
+
for (const cookie of result.cookies) headers.append('set-cookie', cookie);
|
|
128
|
+
return new Response(
|
|
129
|
+
result.isBase64Encoded ? Buffer.from(result.body, 'base64') : result.body || null,
|
|
130
|
+
{ status: result.statusCode, headers }
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
```
|
|
134
|
+
where `<your_app_name>` is the name of application set in `package.json`.
|
|
135
|
+
|
|
136
|
+
3. Finally, create the `netlify.toml` file to correctly configure Netlify in handling request to your function:
|
|
137
|
+
```
|
|
138
|
+
[build]
|
|
139
|
+
command = "npm run build"
|
|
140
|
+
publish = "dist/content-sdk-angular/browser"
|
|
141
|
+
|
|
142
|
+
[functions.server]
|
|
143
|
+
# Ship the full dist folder so express.static and any runtime file access work.
|
|
144
|
+
included_files = ["dist/content-sdk-angular/**"]
|
|
145
|
+
|
|
146
|
+
[[redirects]]
|
|
147
|
+
from = "/*"
|
|
148
|
+
status = 200
|
|
149
|
+
to = "/.netlify/functions/server/:splat"
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
4. In Netlify portal, set the required Content SDK environment variables. Additionally, set `NG_ALLOWED_HOSTS` environment variable to allow netlify URLs:
|
|
154
|
+
```
|
|
155
|
+
NG_ALLOWED_HOSTS=*.netlify.app`
|
|
156
|
+
```
|
|
@@ -9,7 +9,6 @@ import express from 'express';
|
|
|
9
9
|
import { join } from 'node:path';
|
|
10
10
|
import memoryDriver from 'unstorage/drivers/memory';
|
|
11
11
|
import {
|
|
12
|
-
createCacheAdminMiddleware,
|
|
13
12
|
createEditingConfigMiddleware,
|
|
14
13
|
createEditingRenderMiddleware,
|
|
15
14
|
createLoaderCache,
|
|
@@ -76,9 +75,6 @@ app.use(
|
|
|
76
75
|
})
|
|
77
76
|
);
|
|
78
77
|
|
|
79
|
-
/** Admin endpoints for cache inspection and invalidation (see `/api/_cache`). */
|
|
80
|
-
app.use(createCacheAdminMiddleware({ cache: loaderCache, endpoint: '/api/_cache' }));
|
|
81
|
-
|
|
82
78
|
/**
|
|
83
79
|
* Editing config endpoint (`/api/editing/config`). Replies with the registered
|
|
84
80
|
* component map keys and `editMode: 'metadata'` so Sitecore Pages can negotiate
|
|
@@ -198,3 +194,4 @@ if (isMainModule(import.meta.url)) {
|
|
|
198
194
|
* Request handler used by the Angular CLI (for dev-server and during build) or Firebase Cloud Functions.
|
|
199
195
|
*/
|
|
200
196
|
export const reqHandler = createNodeRequestHandler(app);
|
|
197
|
+
export default reqHandler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-content-sdk-app",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-canary.20260720140034",
|
|
4
4
|
"description": "Sitecore Content SDK initializer",
|
|
5
5
|
"bin": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@sitecore-content-sdk/analytics-core": "^2.1.1",
|
|
42
|
-
"@sitecore-content-sdk/angular": "
|
|
42
|
+
"@sitecore-content-sdk/angular": "0.2.0-canary.20260720140034",
|
|
43
43
|
"@sitecore-content-sdk/cli": "^2.2.0",
|
|
44
44
|
"@sitecore-content-sdk/events": "^2.1.1",
|
|
45
45
|
"@sitecore-content-sdk/nextjs": "^2.2.1",
|