Skip to content

Commit 0fcc92e

Browse files
authored
chore: fix TS types, document CUSTOM_BUILD_COMMAND, enable HTTP streaming (#192)
1 parent d11c3b2 commit 0fcc92e

File tree

8 files changed

+1319
-947
lines changed

8 files changed

+1319
-947
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@ Oryx, Azure's build system, may attempt to build your application with an EOL ve
5353
}
5454
```
5555

56+
### CUSTOM_BUILD_COMMAND
57+
58+
If `CUSTOM_BUILD_COMMAND` is not provided to the github action, the [azure swa github action](https://docs.microsoft.com/en-us/azure/static-web-apps/build-configuration?tabs=github-actions) runs the following (as of 03.03.2025)
59+
60+
```yaml
61+
npm install # this could lead to differences in final used dependencies
62+
npm run build
63+
npm run build:azure # Although according to docs "...the workflow tries to run the npm run build or npm run build:azure commands"
64+
npm install # in build/server
65+
```
66+
67+
If you wish to control that `npm ci` is executed instead of `npm install`, define the `CUSTOM_BUILD_COMMAND` environment variable for the build in combination with `skip_api_build: true`. In this case you will need to execute `npm install` in the `build/server` directory with api functions manually.
68+
69+
```yaml
70+
...
71+
env:
72+
# npm install in build/server should be executed manually
73+
# or execute npm ci before this action
74+
CUSTOM_BUILD_COMMAND: "npm ci && npm run build && npm install --prefix ./build/server --omit=dev"
75+
with:
76+
skip_api_build: true
77+
...
78+
```
79+
5680
## Running locally with the Azure SWA CLI
5781

5882
You can debug using the [Azure Static Web Apps CLI](https://github.com/Azure/static-web-apps-cli). Note that the CLI is currently in preview and you may encounter issues.

demo/src/routes/styles.css

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
@import '@fontsource/fira-mono';
22

33
:root {
4-
--font-body: Arial, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
5-
Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
4+
--font-body:
5+
Arial, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
6+
'Open Sans', 'Helvetica Neue', sans-serif;
67
--font-mono: 'Fira Mono', monospace;
78
--color-bg-0: rgb(202, 216, 228);
89
--color-bg-1: hsl(209, 36%, 86%);
@@ -22,11 +23,8 @@ body {
2223
background-attachment: fixed;
2324
background-color: var(--color-bg-1);
2425
background-size: 100vw 100vh;
25-
background-image: radial-gradient(
26-
50% 50% at 50% 50%,
27-
rgba(255, 255, 255, 0.75) 0%,
28-
rgba(255, 255, 255, 0) 100%
29-
),
26+
background-image:
27+
radial-gradient(50% 50% at 50% 50%, rgba(255, 255, 255, 0.75) 0%, rgba(255, 255, 255, 0) 100%),
3028
linear-gradient(180deg, var(--color-bg-0) 0%, var(--color-bg-1) 15%, var(--color-bg-2) 50%);
3129
}
3230

files/api/.funcignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.js.map
2+
*.ts
3+
.git*
4+
.vscode
5+
__azurite_db*__.json
6+
__blobstorage__
7+
__queuestorage__
8+
local.settings.json
9+
test
10+
tsconfig.json

files/entry.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
getClientPrincipalFromHeaders,
77
splitCookiesFromHeaders
88
} from './headers';
9-
import { app } from '@azure/functions';
9+
import { app, HttpResponse } from '@azure/functions';
1010

1111
// replaced at build time
1212
// @ts-expect-error
@@ -20,9 +20,12 @@ const initialized = server.init({ env: process.env });
2020
/**
2121
* @typedef {import('@azure/functions').InvocationContext} InvocationContext
2222
* @typedef {import('@azure/functions').HttpRequest} HttpRequest
23-
* @typedef {import('@azure/functions').HttpResponse} HttpResponse
2423
*/
2524

25+
app.setup({
26+
enableHttpStream: true
27+
});
28+
2629
app.http('sk_render', {
2730
methods: ['HEAD', 'GET', 'POST', 'DELETE', 'PUT', 'OPTIONS'],
2831
/**
@@ -96,7 +99,6 @@ function toRequest(httpRequest) {
9699
return new Request(originalUrl, {
97100
method: httpRequest.method,
98101
headers: new Headers(headers),
99-
// @ts-ignore
100102
body: httpRequest.body,
101103
duplex: 'half'
102104
});
@@ -109,12 +111,11 @@ function toRequest(httpRequest) {
109111
async function toResponse(rendered) {
110112
const { headers, cookies } = splitCookiesFromHeaders(rendered.headers);
111113

112-
return {
114+
return new HttpResponse({
113115
status: rendered.status,
114-
// @ts-ignore
115116
body: rendered.body,
116117
headers,
117118
cookies,
118119
enableContentNegotiation: false
119-
};
120+
});
120121
}

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ declare global {
3939
*/
4040
context: InvocationContext;
4141

42-
user: HttpRequestUser;
42+
user: HttpRequestUser | null;
4343

4444
clientPrincipal?: ClientPrincipal;
4545
}

0 commit comments

Comments
 (0)