svelte-adapter-uws 0.1.0 → 0.1.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 CHANGED
@@ -60,6 +60,8 @@ npm install uNetworking/uWebSockets.js#v20.60.0
60
60
  ```
61
61
 
62
62
  > **Note:** uWebSockets.js is a native C++ addon installed directly from GitHub, not from npm. It may not compile on all platforms. Check the [uWebSockets.js README](https://github.com/uNetworking/uWebSockets.js) if you have issues.
63
+ >
64
+ > **Docker:** Use `node:22-trixie-slim` or another glibc >= 2.38 image. Bookworm-based images and Alpine won't work. See [Deploying with Docker](#deploying-with-docker).
63
65
 
64
66
  If you plan to use WebSockets during development, also install `ws`:
65
67
 
@@ -1119,20 +1121,27 @@ The only difference is how you receive props. The client store API (`on`, `crud`
1119
1121
  uWebSockets.js is a native C++ addon, so your Docker image needs to match the platform it was compiled for. Build inside the container to be safe.
1120
1122
 
1121
1123
  ```dockerfile
1122
- FROM node:20-slim
1124
+ FROM node:22-trixie-slim AS build
1125
+
1126
+ # git is required - uWebSockets.js is installed from GitHub, not npm
1127
+ RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
1123
1128
 
1124
1129
  WORKDIR /app
1125
1130
 
1126
- # Copy package files and install dependencies
1127
1131
  COPY package*.json ./
1128
1132
  RUN npm ci
1129
1133
 
1130
- # Copy source and build
1131
1134
  COPY . .
1132
1135
  RUN npm run build
1133
1136
 
1134
- # Only the build output is needed at runtime
1135
- # (but node_modules must stay for uWebSockets.js native addon)
1137
+ # Runtime stage - no git needed
1138
+ FROM node:22-trixie-slim
1139
+
1140
+ WORKDIR /app
1141
+ COPY --from=build /app/build build/
1142
+ COPY --from=build /app/node_modules node_modules/
1143
+ COPY package.json .
1144
+
1136
1145
  EXPOSE 3000
1137
1146
  CMD ["node", "build"]
1138
1147
  ```
@@ -1150,7 +1159,7 @@ docker run -p 3000:3000 \
1150
1159
  my-app
1151
1160
  ```
1152
1161
 
1153
- > **Tip:** Don't use Alpine (`node:20-alpine`) - uWebSockets.js prebuilt binaries are compiled against glibc, not musl. If you must use Alpine, you'll need to compile from source.
1162
+ > **Important:** Use Debian Trixie or Ubuntu 24.04+ based images (glibc >= 2.38). Bookworm-based images (`node:*-slim`, `node:*-bookworm`) ship glibc 2.36 which is too old for uWebSockets.js. Don't use Alpine either - uWebSockets.js binaries are compiled against glibc, not musl.
1154
1163
 
1155
1164
  ---
1156
1165
 
@@ -1395,9 +1404,10 @@ npm install uNetworking/uWebSockets.js#v20.60.0
1395
1404
  sudo apt install build-essential
1396
1405
  ```
1397
1406
 
1398
- **On Docker:** Use a Node.js image that includes build tools:
1407
+ **On Docker:** Use a Trixie-based image with git:
1399
1408
  ```dockerfile
1400
- FROM node:20
1409
+ FROM node:22-trixie-slim
1410
+ RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
1401
1411
  ```
1402
1412
 
1403
1413
  ### "I can't see what's happening with WebSocket messages"
package/files/handler.js CHANGED
@@ -10,7 +10,7 @@ import { manifest, prerendered, base } from 'MANIFEST';
10
10
  import { env } from 'ENV';
11
11
  import * as wsModule from 'WS_HANDLER';
12
12
  import { parseCookies } from './cookies.js';
13
- import { mimeLookup, splitCookiesString, parse_as_bytes, parse_origin } from './utils.js';
13
+ import { mimeLookup, parse_as_bytes, parse_origin } from './utils.js';
14
14
 
15
15
  /* global ENV_PREFIX */
16
16
  /* global PRECOMPRESS */
@@ -497,11 +497,13 @@ async function handleSSR(res, method, url, headers, remoteAddress, state, abortS
497
497
  return;
498
498
  }
499
499
  console.error('SSR error:', err);
500
- res.cork(() => {
501
- res.writeStatus('500 Internal Server Error');
502
- res.writeHeader('content-type', 'text/plain');
503
- res.end('Internal Server Error');
504
- });
500
+ if (!state.aborted) {
501
+ res.cork(() => {
502
+ res.writeStatus('500 Internal Server Error');
503
+ res.writeHeader('content-type', 'text/plain');
504
+ res.end('Internal Server Error');
505
+ });
506
+ }
505
507
  }
506
508
  }
507
509
 
@@ -515,15 +517,11 @@ async function handleSSR(res, method, url, headers, remoteAddress, state, abortS
515
517
  function writeHeaders(res, response) {
516
518
  res.writeStatus(String(response.status));
517
519
  for (const [key, value] of response.headers) {
518
- if (key === 'set-cookie') {
519
- for (const cookie of splitCookiesString(
520
- /** @type {string} */ (response.headers.get(key))
521
- )) {
522
- res.writeHeader(key, cookie);
523
- }
524
- } else {
525
- res.writeHeader(key, value);
526
- }
520
+ if (key === 'set-cookie') continue;
521
+ res.writeHeader(key, value);
522
+ }
523
+ for (const cookie of response.headers.getSetCookie()) {
524
+ res.writeHeader('set-cookie', cookie);
527
525
  }
528
526
  }
529
527
 
@@ -535,6 +533,7 @@ function writeHeaders(res, response) {
535
533
  async function writeResponse(res, response, state) {
536
534
  // No body - write headers + end in a single cork (one syscall)
537
535
  if (!response.body) {
536
+ if (state.aborted) return;
538
537
  res.cork(() => {
539
538
  writeHeaders(res, response);
540
539
  res.end();
@@ -543,6 +542,7 @@ async function writeResponse(res, response, state) {
543
542
  }
544
543
 
545
544
  if (response.body.locked) {
545
+ if (state.aborted) return;
546
546
  res.cork(() => {
547
547
  res.writeStatus('500 Internal Server Error');
548
548
  res.writeHeader('content-type', 'text/plain');
@@ -576,6 +576,7 @@ async function writeResponse(res, response, state) {
576
576
  }
577
577
 
578
578
  // Multi-chunk streaming response - write headers + first two chunks in one cork
579
+ if (state.aborted) return;
579
580
  res.cork(() => {
580
581
  writeHeaders(res, response);
581
582
  res.write(first.value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-adapter-uws",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "SvelteKit adapter for uWebSockets.js - high-performance C++ HTTP server with built-in WebSocket support",
5
5
  "author": "Kevin Radziszewski",
6
6
  "license": "MIT",