@react-router/express 0.0.0-experimental-c0856287f

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/CHANGELOG.md ADDED
@@ -0,0 +1,422 @@
1
+ # `@remix-run/express`
2
+
3
+ ## 2.9.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies:
8
+ - `@remix-run/node@2.9.0`
9
+
10
+ ## 2.8.1
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies:
15
+ - `@remix-run/node@2.8.1`
16
+
17
+ ## 2.8.0
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies:
22
+ - `@remix-run/node@2.8.0`
23
+
24
+ ## 2.7.2
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies:
29
+ - `@remix-run/node@2.7.2`
30
+
31
+ ## 2.7.1
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated dependencies:
36
+ - `@remix-run/node@2.7.1`
37
+
38
+ ## 2.7.0
39
+
40
+ ### Minor Changes
41
+
42
+ - Vite: Add a new `basename` option to the Vite plugin, allowing users to set the internal React Router [`basename`](https://reactrouter.com/en/main/routers/create-browser-router#basename) in order to to serve their applications underneath a subpath ([#8145](https://github.com/remix-run/remix/pull/8145))
43
+
44
+ ### Patch Changes
45
+
46
+ - Use `req.originalUrl` instead of `req.url` so that Remix sees the full URL ([#8145](https://github.com/remix-run/remix/pull/8145))
47
+
48
+ - Remix relies on the knowing the full URL to ensure that server and client code can function together, and does not support URL rewriting prior to the Remix handler
49
+
50
+ - Updated dependencies:
51
+ - `@remix-run/node@2.7.0`
52
+
53
+ ## 2.6.0
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies:
58
+ - `@remix-run/node@2.6.0`
59
+
60
+ ## 2.5.1
61
+
62
+ ### Patch Changes
63
+
64
+ - Updated dependencies:
65
+ - `@remix-run/node@2.5.1`
66
+
67
+ ## 2.5.0
68
+
69
+ ### Patch Changes
70
+
71
+ - Updated dependencies:
72
+ - `@remix-run/node@2.5.0`
73
+
74
+ ## 2.4.1
75
+
76
+ ### Patch Changes
77
+
78
+ - Updated dependencies:
79
+ - `@remix-run/node@2.4.1`
80
+
81
+ ## 2.4.0
82
+
83
+ ### Patch Changes
84
+
85
+ - Updated dependencies:
86
+ - `@remix-run/node@2.4.0`
87
+
88
+ ## 2.3.1
89
+
90
+ ### Patch Changes
91
+
92
+ - Updated dependencies:
93
+ - `@remix-run/node@2.3.1`
94
+
95
+ ## 2.3.0
96
+
97
+ ### Patch Changes
98
+
99
+ - Fix flash of unstyled content on initial page load in Vite dev when using a custom Express server ([#7937](https://github.com/remix-run/remix/pull/7937))
100
+ - Updated dependencies:
101
+ - `@remix-run/node@2.3.0`
102
+
103
+ ## 2.2.0
104
+
105
+ ### Patch Changes
106
+
107
+ - Allow the `@remix-run/express` adapter to work behind a proxy when using `app.enable('trust proxy')` ([#7323](https://github.com/remix-run/remix/pull/7323))
108
+ - Previously, this used `req.get('host')` to construct the Remix `Request`, but that does not respect `X-Forwarded-Host`
109
+ - This now uses `req.hostname` which will respect `X-Forwarded-Host`
110
+ - Updated dependencies:
111
+ - `@remix-run/node@2.2.0`
112
+
113
+ ## 2.1.0
114
+
115
+ ### Patch Changes
116
+
117
+ - Flush headers for `text/event-stream` responses ([#7619](https://github.com/remix-run/remix/pull/7619))
118
+ - Updated dependencies:
119
+ - `@remix-run/node@2.1.0`
120
+
121
+ ## 2.0.1
122
+
123
+ ### Patch Changes
124
+
125
+ - Updated dependencies:
126
+ - `@remix-run/node@2.0.1`
127
+
128
+ ## 2.0.0
129
+
130
+ ### Major Changes
131
+
132
+ - Require Node >=18.0.0 ([#6939](https://github.com/remix-run/remix/pull/6939))
133
+
134
+ - For preparation of using Node's built in fetch implementation, installing the fetch globals is now a responsibility of the app server ([#7009](https://github.com/remix-run/remix/pull/7009))
135
+
136
+ - If you are using `remix-serve`, nothing is required
137
+ - If you are using your own app server, you will need to install the globals yourself
138
+
139
+ ```js filename=server.js
140
+ import { installGlobals } from "@remix-run/node";
141
+
142
+ installGlobals();
143
+ ```
144
+
145
+ - `source-map-support` is now a responsibility of the app server ([#7009](https://github.com/remix-run/remix/pull/7009))
146
+
147
+ - If you are using `remix-serve`, nothing is required
148
+ - If you are using your own app server, you will need to install [`source-map-support`](https://www.npmjs.com/package/source-map-support) yourself.
149
+
150
+ ```sh
151
+ npm i source-map-support
152
+ ```
153
+
154
+ ```js filename=server.js
155
+ import sourceMapSupport from "source-map-support";
156
+ sourceMapSupport.install();
157
+ ```
158
+
159
+ ### Patch Changes
160
+
161
+ - Switch to `headers.entries()` instead of non-spec-compliant `headers.raw()` in `sendRemixResponse` ([#7150](https://github.com/remix-run/remix/pull/7150))
162
+ - Remove references to fetch polyfills in node and arc adapters ([#7230](https://github.com/remix-run/remix/pull/7230))
163
+ - Updated dependencies:
164
+ - `@remix-run/node@2.0.0`
165
+ - `@remix-run/web-fetch@4.4.0`
166
+ - `@remix-run/web-file@3.1.0`
167
+ - `@remix-run/web-stream@1.1.0`
168
+
169
+ ## 1.19.3
170
+
171
+ ### Patch Changes
172
+
173
+ - Updated dependencies:
174
+ - `@remix-run/node@1.19.3`
175
+
176
+ ## 1.19.2
177
+
178
+ ### Patch Changes
179
+
180
+ - Updated dependencies:
181
+ - `@remix-run/node@1.19.2`
182
+
183
+ ## 1.19.1
184
+
185
+ ### Patch Changes
186
+
187
+ - Updated dependencies:
188
+ - `@remix-run/node@1.19.1`
189
+
190
+ ## 1.19.0
191
+
192
+ ### Patch Changes
193
+
194
+ - Updated dependencies:
195
+ - `@remix-run/node@1.19.0`
196
+
197
+ ## 1.18.1
198
+
199
+ ### Patch Changes
200
+
201
+ - Updated dependencies:
202
+ - `@remix-run/node@1.18.1`
203
+
204
+ ## 1.18.0
205
+
206
+ ### Patch Changes
207
+
208
+ - Updated dependencies:
209
+ - `@remix-run/node@1.18.0`
210
+
211
+ ## 1.17.1
212
+
213
+ ### Patch Changes
214
+
215
+ - Updated dependencies:
216
+ - `@remix-run/node@1.17.1`
217
+
218
+ ## 1.17.0
219
+
220
+ ### Patch Changes
221
+
222
+ - Updated dependencies:
223
+ - `@remix-run/node@1.17.0`
224
+
225
+ ## 1.16.1
226
+
227
+ ### Patch Changes
228
+
229
+ - Updated dependencies:
230
+ - `@remix-run/node@1.16.1`
231
+
232
+ ## 1.16.0
233
+
234
+ ### Patch Changes
235
+
236
+ - feat: support async `getLoadContext` in all adapters ([#6170](https://github.com/remix-run/remix/pull/6170))
237
+ - Updated dependencies:
238
+ - `@remix-run/node@1.16.0`
239
+
240
+ ## 1.15.0
241
+
242
+ ### Patch Changes
243
+
244
+ - Updated dependencies:
245
+ - `@remix-run/node@1.15.0`
246
+
247
+ ## 1.14.3
248
+
249
+ ### Patch Changes
250
+
251
+ - Updated dependencies:
252
+ - `@remix-run/node@1.14.3`
253
+
254
+ ## 1.14.2
255
+
256
+ ### Patch Changes
257
+
258
+ - Updated dependencies:
259
+ - `@remix-run/node@1.14.2`
260
+
261
+ ## 1.14.1
262
+
263
+ ### Patch Changes
264
+
265
+ - Updated dependencies:
266
+ - `@remix-run/node@1.14.1`
267
+
268
+ ## 1.14.0
269
+
270
+ ### Patch Changes
271
+
272
+ - Updated dependencies:
273
+ - `@remix-run/node@1.14.0`
274
+
275
+ ## 1.13.0
276
+
277
+ ### Patch Changes
278
+
279
+ - Fix fetch `Request` creation for incoming URLs with double slashes ([#5336](https://github.com/remix-run/remix/pull/5336))
280
+ - Updated dependencies:
281
+ - `@remix-run/node@1.13.0`
282
+
283
+ ## 1.12.0
284
+
285
+ ### Patch Changes
286
+
287
+ - Updated dependencies:
288
+ - `@remix-run/node@1.12.0`
289
+
290
+ ## 1.11.1
291
+
292
+ ### Patch Changes
293
+
294
+ - Updated dependencies:
295
+ - `@remix-run/node@1.11.1`
296
+
297
+ ## 1.11.0
298
+
299
+ ### Patch Changes
300
+
301
+ - Updated dependencies:
302
+ - `@remix-run/node@1.11.0`
303
+
304
+ ## 1.10.1
305
+
306
+ ### Patch Changes
307
+
308
+ - Updated dependencies:
309
+ - `@remix-run/node@1.10.1`
310
+
311
+ ## 1.10.0
312
+
313
+ ### Patch Changes
314
+
315
+ - Updated dependencies:
316
+ - `@remix-run/node@1.10.0`
317
+
318
+ ## 1.9.0
319
+
320
+ ### Patch Changes
321
+
322
+ - Updated dependencies:
323
+ - `@remix-run/node@1.9.0`
324
+
325
+ ## 1.8.2
326
+
327
+ ### Patch Changes
328
+
329
+ - Updated dependencies:
330
+ - `@remix-run/node@1.8.2`
331
+
332
+ ## 1.8.1
333
+
334
+ ### Patch Changes
335
+
336
+ - Updated dependencies:
337
+ - `@remix-run/node@1.8.1`
338
+
339
+ ## 1.8.0
340
+
341
+ ### Patch Changes
342
+
343
+ - Updated dependencies:
344
+ - `@remix-run/node@1.8.0`
345
+
346
+ ## 1.7.6
347
+
348
+ ### Patch Changes
349
+
350
+ - Updated dependencies:
351
+ - `@remix-run/node@1.7.6`
352
+
353
+ ## 1.7.5
354
+
355
+ ### Patch Changes
356
+
357
+ - Updated dependencies:
358
+ - `@remix-run/node@1.7.5`
359
+
360
+ ## 1.7.4
361
+
362
+ ### Patch Changes
363
+
364
+ - Updated dependencies:
365
+ - `@remix-run/node@1.7.4`
366
+
367
+ ## 1.7.3
368
+
369
+ ### Patch Changes
370
+
371
+ - Updated dependencies:
372
+ - `@remix-run/node@1.7.3`
373
+
374
+ ## 1.7.2
375
+
376
+ ### Patch Changes
377
+
378
+ - Updated dependencies:
379
+ - `@remix-run/node@1.7.2`
380
+
381
+ ## 1.7.1
382
+
383
+ ### Patch Changes
384
+
385
+ - Ensured that requests are properly aborted on closing of a `Response` instead of `Request` ([#3626](https://github.com/remix-run/remix/pull/3626))
386
+ - Updated dependencies:
387
+ - `@remix-run/node@1.7.1`
388
+
389
+ ## 1.7.0
390
+
391
+ ### Patch Changes
392
+
393
+ - Updated dependencies:
394
+ - `@remix-run/node@1.7.0`
395
+
396
+ ## 1.6.8
397
+
398
+ ### Patch Changes
399
+
400
+ - Updated dependencies:
401
+ - `@remix-run/node@1.6.8`
402
+
403
+ ## 1.6.7
404
+
405
+ ### Patch Changes
406
+
407
+ - Updated dependencies:
408
+ - `@remix-run/node@1.6.7`
409
+
410
+ ## 1.6.6
411
+
412
+ ### Patch Changes
413
+
414
+ - Updated dependencies:
415
+ - `@remix-run/node@1.6.6`
416
+
417
+ ## 1.6.5
418
+
419
+ ### Patch Changes
420
+
421
+ - Updated dependencies
422
+ - `@remix-run/node@1.6.5`
package/LICENSE.md ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) React Training LLC 2015-2019
4
+ Copyright (c) Remix Software Inc. 2020-2021
5
+ Copyright (c) Shopify Inc. 2022-2023
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # Welcome to Remix!
2
+
3
+ [Remix](https://remix.run) is a web framework that helps you build better websites with React.
4
+
5
+ To get started, open a new shell and run:
6
+
7
+ ```sh
8
+ npx create-remix@latest
9
+ ```
10
+
11
+ Then follow the prompts you see in your terminal.
12
+
13
+ For more information about Remix, [visit remix.run](https://remix.run)!
@@ -0,0 +1,2 @@
1
+ export type { GetLoadContextFunction, RequestHandler } from "./server";
2
+ export { createRequestHandler } from "./server";
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @react-router/express v0.0.0-experimental-c0856287f
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ 'use strict';
12
+
13
+ Object.defineProperty(exports, '__esModule', { value: true });
14
+
15
+ var server = require('./server.js');
16
+
17
+
18
+
19
+ exports.createRequestHandler = server.createRequestHandler;
@@ -0,0 +1,24 @@
1
+ /// <reference lib="dom.iterable" />
2
+ import type * as express from "express";
3
+ import type { AppLoadContext, ServerBuild } from "@react-router/node";
4
+ /**
5
+ * A function that returns the value to use as `context` in route `loader` and
6
+ * `action` functions.
7
+ *
8
+ * You can think of this as an escape hatch that allows you to pass
9
+ * environment/platform-specific values through to your loader/action, such as
10
+ * values that are generated by Express middleware like `req.session`.
11
+ */
12
+ export type GetLoadContextFunction = (req: express.Request, res: express.Response) => Promise<AppLoadContext> | AppLoadContext;
13
+ export type RequestHandler = (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
14
+ /**
15
+ * Returns a request handler for Express that serves the response using Remix.
16
+ */
17
+ export declare function createRequestHandler({ build, getLoadContext, mode, }: {
18
+ build: ServerBuild | (() => Promise<ServerBuild>);
19
+ getLoadContext?: GetLoadContextFunction;
20
+ mode?: string;
21
+ }): RequestHandler;
22
+ export declare function createRemixHeaders(requestHeaders: express.Request["headers"]): Headers;
23
+ export declare function createRemixRequest(req: express.Request, res: express.Response): Request;
24
+ export declare function sendRemixResponse(res: express.Response, nodeResponse: Response): Promise<void>;
package/dist/server.js ADDED
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @react-router/express v0.0.0-experimental-c0856287f
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ 'use strict';
12
+
13
+ Object.defineProperty(exports, '__esModule', { value: true });
14
+
15
+ var node = require('@react-router/node');
16
+
17
+ // IDK why this is needed when it's in the tsconfig..........
18
+ /**
19
+ * Returns a request handler for Express that serves the response using Remix.
20
+ */
21
+ function createRequestHandler({
22
+ build,
23
+ getLoadContext,
24
+ mode = process.env.NODE_ENV
25
+ }) {
26
+ let handleRequest = node.createRequestHandler(build, mode);
27
+ return async (req, res, next) => {
28
+ try {
29
+ let request = createRemixRequest(req, res);
30
+ let loadContext = await (getLoadContext === null || getLoadContext === void 0 ? void 0 : getLoadContext(req, res));
31
+ let response = await handleRequest(request, loadContext);
32
+ await sendRemixResponse(res, response);
33
+ } catch (error) {
34
+ // Express doesn't support async functions, so we have to pass along the
35
+ // error manually using next().
36
+ next(error);
37
+ }
38
+ };
39
+ }
40
+ function createRemixHeaders(requestHeaders) {
41
+ let headers = new Headers();
42
+ for (let [key, values] of Object.entries(requestHeaders)) {
43
+ if (values) {
44
+ if (Array.isArray(values)) {
45
+ for (let value of values) {
46
+ headers.append(key, value);
47
+ }
48
+ } else {
49
+ headers.set(key, values);
50
+ }
51
+ }
52
+ }
53
+ return headers;
54
+ }
55
+ function createRemixRequest(req, res) {
56
+ var _req$get, _req$get2;
57
+ // req.hostname doesn't include port information so grab that from
58
+ // `X-Forwarded-Host` or `Host`
59
+ let [, hostnamePort] = ((_req$get = req.get("X-Forwarded-Host")) === null || _req$get === void 0 ? void 0 : _req$get.split(":")) ?? [];
60
+ let [, hostPort] = ((_req$get2 = req.get("host")) === null || _req$get2 === void 0 ? void 0 : _req$get2.split(":")) ?? [];
61
+ let port = hostnamePort || hostPort;
62
+ // Use req.hostname here as it respects the "trust proxy" setting
63
+ let resolvedHost = `${req.hostname}${port ? `:${port}` : ""}`;
64
+ // Use `req.originalUrl` so Remix is aware of the full path
65
+ let url = new URL(`${req.protocol}://${resolvedHost}${req.originalUrl}`);
66
+ // Abort action/loaders once we can no longer write a response
67
+ let controller = new AbortController();
68
+ res.on("close", () => controller.abort());
69
+ let init = {
70
+ method: req.method,
71
+ headers: createRemixHeaders(req.headers),
72
+ signal: controller.signal
73
+ };
74
+ if (req.method !== "GET" && req.method !== "HEAD") {
75
+ init.body = node.createReadableStreamFromReadable(req);
76
+ init.duplex = "half";
77
+ }
78
+ return new Request(url.href, init);
79
+ }
80
+ async function sendRemixResponse(res, nodeResponse) {
81
+ var _nodeResponse$headers;
82
+ res.statusMessage = nodeResponse.statusText;
83
+ res.status(nodeResponse.status);
84
+ for (let [key, value] of nodeResponse.headers.entries()) {
85
+ res.append(key, value);
86
+ }
87
+ if ((_nodeResponse$headers = nodeResponse.headers.get("Content-Type")) !== null && _nodeResponse$headers !== void 0 && _nodeResponse$headers.match(/text\/event-stream/i)) {
88
+ res.flushHeaders();
89
+ }
90
+ if (nodeResponse.body) {
91
+ await node.writeReadableStreamToWritable(nodeResponse.body, res);
92
+ } else {
93
+ res.end();
94
+ }
95
+ }
96
+
97
+ exports.createRemixHeaders = createRemixHeaders;
98
+ exports.createRemixRequest = createRemixRequest;
99
+ exports.createRequestHandler = createRequestHandler;
100
+ exports.sendRemixResponse = sendRemixResponse;
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@react-router/express",
3
+ "version": "0.0.0-experimental-c0856287f",
4
+ "description": "Express server request handler for React Router",
5
+ "bugs": {
6
+ "url": "https://github.com/remix-run/react-router/issues"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/remix-run/react-router",
11
+ "directory": "packages/remix-express"
12
+ },
13
+ "license": "MIT",
14
+ "main": "dist/index.js",
15
+ "typings": "dist/index.d.ts",
16
+ "dependencies": {
17
+ "@react-router/node": "0.0.0-experimental-c0856287f"
18
+ },
19
+ "devDependencies": {
20
+ "@types/express": "^4.17.9",
21
+ "@types/node": "^18.17.1",
22
+ "@types/supertest": "^2.0.10",
23
+ "express": "^4.17.1",
24
+ "node-mocks-http": "^1.10.1",
25
+ "supertest": "^6.3.3",
26
+ "typescript": "^5.1.6"
27
+ },
28
+ "peerDependencies": {
29
+ "express": "^4.17.1",
30
+ "typescript": "^5.1.0"
31
+ },
32
+ "peerDependenciesMeta": {
33
+ "typescript": {
34
+ "optional": true
35
+ }
36
+ },
37
+ "engines": {
38
+ "node": ">=18.0.0"
39
+ },
40
+ "files": [
41
+ "dist/",
42
+ "CHANGELOG.md",
43
+ "LICENSE.md",
44
+ "README.md"
45
+ ],
46
+ "scripts": {
47
+ "tsc": "tsc"
48
+ }
49
+ }