You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert

13
+

14
14
15
15
```typescript twoslash
16
16
import { Router } from'@neabyte/deserve'
@@ -31,7 +31,7 @@ Ini menyajikan file dari direktori `public/` di path URL `/static`:
-`GET /static/.env` → ditolak dengan **404** sebelum pembacaan apa pun
35
35
36
36
37
37
## Cara Kerja
@@ -81,7 +81,7 @@ router.static('/assets', {
81
81
82
82
### `etag`
83
83
84
-
Aktifkan generasi ETag untuk caching. Tag adalah hash SHA-256 dari ukuran file dan waktu modifikasi, bukan isi file penuh, jadi tetap murah dihitung:
84
+
Aktifkan pembuatan ETag untuk caching. Tag adalah hash SHA-256 dari ukuran file dan waktu modifikasi, bukan isi file penuh, jadi tetap murah dihitung:
85
85
86
86
```typescript twoslash
87
87
import { Router } from'@neabyte/deserve'
@@ -116,12 +116,22 @@ router.static('/assets', {
116
116
})
117
117
```
118
118
119
+
## Permintaan Byte-Range
120
+
121
+
Response statis mendukung satu [byte range](https://www.rfc-editor.org/rfc/rfc7233) sehingga klien bisa mengambil sebagian berkas, yang diandalkan oleh penggeser video atau unduhan yang bisa dilanjutkan. Setiap response statis mengumumkan `Accept-Ranges: bytes`, dan request yang membawa satu header `Range` kontigu dijawab dengan jendela yang cocok:
122
+
123
+
-**Satu range valid** mengembalikan **206 Partial Content** dengan header `Content-Range: bytes start-end/size` dan hanya byte itu yang dialirkan dari disk.
124
+
-**Range tak terpenuhi** yang menyebut jendela melewati ukuran berkas mengembalikan **416 Range Not Satisfiable** dengan `Content-Range: bytes */size`.
125
+
-**Range yang tidak ada, multi-bagian, atau tidak valid** kembali menyajikan berkas penuh seperti sebelumnya.
126
+
127
+
Hanya byte di dalam jendela yang diminta yang dibaca, dan handle berkas dilepas begitu jendela terkirim, error, atau dibatalkan.
128
+
119
129
## Resolusi File dan Keamanan
120
130
121
131
Penyajian static memetakan path URL ke file di bawah direktori yang dikonfigurasi, dengan beberapa aturan bawaan:
122
132
123
133
-**Index fallback** - request ke root route menyajikan `index.html` dari direktori.
124
-
-**Content type** - tipe dipilih dari ekstensi file. Aset web umum seperti HTML, CSS, JavaScript, JSON, images, fonts, dan dokumen sudah dipetakan langsung, dan ekstensi tidak dikenal jatuh ke`application/octet-stream`.
134
+
-**Content type** - tipe dipilih dari ekstensi file. Aset web umum seperti HTML, CSS, JavaScript, JSON, images, fonts, dan dokumen sudah dipetakan langsung, dan ekstensi tidak dikenal memakai`application/octet-stream`.
125
135
-**Dotfiles diblokir** - segment path apa pun yang namanya diawali `.` ditolak dengan **404**, jadi file seperti `.env`, `.git/config`, atau `..` di awal tidak pernah disajikan. Aturan melihat nama segment, bukan ekstensi, jadi file biasa seperti `report.env` tetap disajikan.
126
136
-**Directory traversal diblokir** - real path hasil resolusi harus tetap di dalam direktori dasar. Path yang lolos keluar, misalnya dibangun dari `..`, ditolak dengan **404**.
Copy file name to clipboardExpand all lines: docs/static-file/basic.md
+12-2Lines changed: 12 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ Serve static files (HTML, CSS, JS, images) using the `static()` method.
10
10
11
11
Serve static files from a directory:
12
12
13
-

13
+

14
14
15
15
```typescript twoslash
16
16
import { Router } from'@neabyte/deserve'
@@ -31,7 +31,7 @@ This serves files from the `public/` directory at the `/static` URL path:
-`GET /static/.env` → rejected with **404** before any read
35
35
36
36
37
37
## How It Works
@@ -116,6 +116,16 @@ router.static('/assets', {
116
116
})
117
117
```
118
118
119
+
## Byte-Range Requests
120
+
121
+
Static responses support a single [byte range](https://www.rfc-editor.org/rfc/rfc7233) so a client can fetch part of a file, which is what a video scrubber or a resumable download relies on. Every static response advertises `Accept-Ranges: bytes`, and a request carrying one contiguous `Range` header is answered with the matched window:
122
+
123
+
-**One valid range** returns **206 Partial Content** with a `Content-Range: bytes start-end/size` header and only those bytes streamed off disk.
124
+
-**An unsatisfiable range** that names a window past the file size returns **416 Range Not Satisfiable** with `Content-Range: bytes */size`.
125
+
-**An absent, multi-part, or malformed range** falls back to the full file as before.
126
+
127
+
Only the bytes inside the requested window are read, and the file handle is released once the window is sent, errors, or is cancelled.
128
+
119
129
## File Resolution and Security
120
130
121
131
Static serving maps a URL path to a file under the configured directory, with a few built-in rules:
0 commit comments