@remix-run/static-middleware 0.4.0 → 0.4.1
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/dist/lib/static.d.ts +3 -3
- package/dist/lib/static.js +6 -6
- package/package.json +15 -15
- package/src/lib/static.ts +8 -8
package/dist/lib/static.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type FileResponseOptions } from '@remix-run/response/file';
|
|
|
3
3
|
/**
|
|
4
4
|
* Function that determines if HTTP Range requests should be supported for a given file.
|
|
5
5
|
*
|
|
6
|
-
* @param file
|
|
6
|
+
* @param file The File object being served
|
|
7
7
|
* @returns true if range requests should be supported
|
|
8
8
|
*/
|
|
9
9
|
export type AcceptRangesFunction = (file: File) => boolean;
|
|
@@ -15,7 +15,7 @@ export interface StaticFilesOptions extends Omit<FileResponseOptions, 'acceptRan
|
|
|
15
15
|
* Filter function to determine which files should be served.
|
|
16
16
|
*
|
|
17
17
|
* @param path The relative path being requested
|
|
18
|
-
* @
|
|
18
|
+
* @returns Whether to serve the file
|
|
19
19
|
*/
|
|
20
20
|
filter?: (path: string) => boolean;
|
|
21
21
|
/**
|
|
@@ -68,7 +68,7 @@ export interface StaticFilesOptions extends Omit<FileResponseOptions, 'acceptRan
|
|
|
68
68
|
*
|
|
69
69
|
* @param root The root directory to serve files from (absolute or relative to cwd)
|
|
70
70
|
* @param options Configuration for file responses
|
|
71
|
-
* @
|
|
71
|
+
* @returns The static files middleware
|
|
72
72
|
*/
|
|
73
73
|
export declare function staticFiles(root: string, options?: StaticFilesOptions): Middleware;
|
|
74
74
|
//# sourceMappingURL=static.d.ts.map
|
package/dist/lib/static.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import * as fsp from 'node:fs/promises';
|
|
3
|
-
import {
|
|
3
|
+
import { openLazyFile } from '@remix-run/fs';
|
|
4
4
|
import { createFileResponse as sendFile } from '@remix-run/response/file';
|
|
5
5
|
import { generateDirectoryListing } from "./directory-listing.js";
|
|
6
6
|
/**
|
|
@@ -11,7 +11,7 @@ import { generateDirectoryListing } from "./directory-listing.js";
|
|
|
11
11
|
*
|
|
12
12
|
* @param root The root directory to serve files from (absolute or relative to cwd)
|
|
13
13
|
* @param options Configuration for file responses
|
|
14
|
-
* @
|
|
14
|
+
* @returns The static files middleware
|
|
15
15
|
*/
|
|
16
16
|
export function staticFiles(root, options = {}) {
|
|
17
17
|
// Ensure root is an absolute path
|
|
@@ -69,17 +69,17 @@ export function staticFiles(root, options = {}) {
|
|
|
69
69
|
}
|
|
70
70
|
if (filePath) {
|
|
71
71
|
let fileName = path.relative(root, filePath);
|
|
72
|
-
let
|
|
72
|
+
let lazyFile = openLazyFile(filePath, { name: fileName });
|
|
73
73
|
let finalFileOptions = { ...fileOptions };
|
|
74
|
-
// If acceptRanges is a function, evaluate it with the
|
|
74
|
+
// If acceptRanges is a function, evaluate it with the lazyFile
|
|
75
75
|
// Otherwise, pass it directly to sendFile
|
|
76
76
|
if (typeof acceptRanges === 'function') {
|
|
77
|
-
finalFileOptions.acceptRanges = acceptRanges(
|
|
77
|
+
finalFileOptions.acceptRanges = acceptRanges(lazyFile);
|
|
78
78
|
}
|
|
79
79
|
else if (acceptRanges !== undefined) {
|
|
80
80
|
finalFileOptions.acceptRanges = acceptRanges;
|
|
81
81
|
}
|
|
82
|
-
return sendFile(
|
|
82
|
+
return sendFile(lazyFile, context.request, finalFileOptions);
|
|
83
83
|
}
|
|
84
84
|
return next();
|
|
85
85
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remix-run/static-middleware",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Middleware for serving static files from the filesystem",
|
|
5
5
|
"author": "Michael Jackson <mjijackson@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,19 +27,19 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^24.6.0",
|
|
30
|
-
"typescript": "
|
|
31
|
-
"@remix-run/fetch-router": "0.
|
|
32
|
-
"@remix-run/form-data-middleware": "0.1.
|
|
33
|
-
"@remix-run/
|
|
34
|
-
"@remix-run/response": "
|
|
35
|
-
"@remix-run/
|
|
30
|
+
"@typescript/native-preview": "7.0.0-dev.20251125.1",
|
|
31
|
+
"@remix-run/fetch-router": "0.15.0",
|
|
32
|
+
"@remix-run/form-data-middleware": "0.1.1",
|
|
33
|
+
"@remix-run/mime": "0.3.0",
|
|
34
|
+
"@remix-run/response": "0.3.0",
|
|
35
|
+
"@remix-run/method-override-middleware": "0.1.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@remix-run/fetch-router": "^0.
|
|
39
|
-
"@remix-run/
|
|
40
|
-
"@remix-run/
|
|
41
|
-
"@remix-run/
|
|
42
|
-
"@remix-run/
|
|
38
|
+
"@remix-run/fetch-router": "^0.15.0",
|
|
39
|
+
"@remix-run/html-template": "^0.3.0",
|
|
40
|
+
"@remix-run/fs": "^0.4.0",
|
|
41
|
+
"@remix-run/mime": "^0.3.0",
|
|
42
|
+
"@remix-run/response": "^0.3.0"
|
|
43
43
|
},
|
|
44
44
|
"keywords": [
|
|
45
45
|
"fetch",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"file-server"
|
|
50
50
|
],
|
|
51
51
|
"scripts": {
|
|
52
|
-
"build": "
|
|
52
|
+
"build": "tsgo -p tsconfig.build.json",
|
|
53
53
|
"clean": "git clean -fdX",
|
|
54
|
-
"test": "node --disable-warning=ExperimentalWarning --test
|
|
55
|
-
"typecheck": "
|
|
54
|
+
"test": "node --disable-warning=ExperimentalWarning --test",
|
|
55
|
+
"typecheck": "tsgo --noEmit"
|
|
56
56
|
}
|
|
57
57
|
}
|
package/src/lib/static.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from 'node:path'
|
|
2
2
|
import * as fsp from 'node:fs/promises'
|
|
3
|
-
import {
|
|
3
|
+
import { openLazyFile } from '@remix-run/fs'
|
|
4
4
|
import type { Middleware } from '@remix-run/fetch-router'
|
|
5
5
|
import { createFileResponse as sendFile, type FileResponseOptions } from '@remix-run/response/file'
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ import { generateDirectoryListing } from './directory-listing.ts'
|
|
|
9
9
|
/**
|
|
10
10
|
* Function that determines if HTTP Range requests should be supported for a given file.
|
|
11
11
|
*
|
|
12
|
-
* @param file
|
|
12
|
+
* @param file The File object being served
|
|
13
13
|
* @returns true if range requests should be supported
|
|
14
14
|
*/
|
|
15
15
|
export type AcceptRangesFunction = (file: File) => boolean
|
|
@@ -22,7 +22,7 @@ export interface StaticFilesOptions extends Omit<FileResponseOptions, 'acceptRan
|
|
|
22
22
|
* Filter function to determine which files should be served.
|
|
23
23
|
*
|
|
24
24
|
* @param path The relative path being requested
|
|
25
|
-
* @
|
|
25
|
+
* @returns Whether to serve the file
|
|
26
26
|
*/
|
|
27
27
|
filter?: (path: string) => boolean
|
|
28
28
|
|
|
@@ -78,7 +78,7 @@ export interface StaticFilesOptions extends Omit<FileResponseOptions, 'acceptRan
|
|
|
78
78
|
*
|
|
79
79
|
* @param root The root directory to serve files from (absolute or relative to cwd)
|
|
80
80
|
* @param options Configuration for file responses
|
|
81
|
-
* @
|
|
81
|
+
* @returns The static files middleware
|
|
82
82
|
*/
|
|
83
83
|
export function staticFiles(root: string, options: StaticFilesOptions = {}): Middleware {
|
|
84
84
|
// Ensure root is an absolute path
|
|
@@ -141,19 +141,19 @@ export function staticFiles(root: string, options: StaticFilesOptions = {}): Mid
|
|
|
141
141
|
|
|
142
142
|
if (filePath) {
|
|
143
143
|
let fileName = path.relative(root, filePath)
|
|
144
|
-
let
|
|
144
|
+
let lazyFile = openLazyFile(filePath, { name: fileName })
|
|
145
145
|
|
|
146
146
|
let finalFileOptions: FileResponseOptions = { ...fileOptions }
|
|
147
147
|
|
|
148
|
-
// If acceptRanges is a function, evaluate it with the
|
|
148
|
+
// If acceptRanges is a function, evaluate it with the lazyFile
|
|
149
149
|
// Otherwise, pass it directly to sendFile
|
|
150
150
|
if (typeof acceptRanges === 'function') {
|
|
151
|
-
finalFileOptions.acceptRanges = acceptRanges(
|
|
151
|
+
finalFileOptions.acceptRanges = acceptRanges(lazyFile)
|
|
152
152
|
} else if (acceptRanges !== undefined) {
|
|
153
153
|
finalFileOptions.acceptRanges = acceptRanges
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
return sendFile(
|
|
156
|
+
return sendFile(lazyFile, context.request, finalFileOptions)
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
return next()
|