Skip to content

Commit a089220

Browse files
Fix for StaticFiles
1 parent 42a6ab9 commit a089220

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

docs/README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,28 @@ uquik
318318
```
319319

320320
### Static files
321-
#### Global
321+
```javascript
322+
const { Server, StaticFiles } = require("uquik");
323+
const path = require("path");
324+
325+
const uquik = new Server();
326+
327+
const static = StaticFiles({
328+
root: path.join(__dirname, "www"), // root directory
329+
indexFile: "index.html", // index file name
330+
compress: true, // enable gzip compression?
331+
compressionThreshold: 1024, // compression threshold
332+
});
333+
334+
uquik.get("/*", static);
335+
uquik.head("/*", static);
336+
337+
uquik
338+
.listen(5000, "127.0.0.1")
339+
.then((socket) => console.log("[Example] Server started"))
340+
.catch((error) => console.log("[Example] Failed to start a server", error));
341+
```
322342

323-
#### Route-specific
324343

325344

326345
### Production

src/StaticFiles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const resolveFile = (file, indexFile = '') => {
1919
} else {
2020
throw new CustomError('404 Not Found', 404)
2121
}
22-
})
22+
}).catch((ex) => { throw new CustomError('404 Not Found', 404) })
2323
}
2424

2525
const destroy = (dataTransfer) => {

0 commit comments

Comments
 (0)