https://github.com/erf/ufilecache
A minimal static file cache handler for uWebSocket.js
https://github.com/erf/ufilecache
Last synced: about 1 year ago
JSON representation
A minimal static file cache handler for uWebSocket.js
- Host: GitHub
- URL: https://github.com/erf/ufilecache
- Owner: erf
- Created: 2024-05-20T13:31:11.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-21T22:18:34.000Z (about 2 years ago)
- Last Synced: 2025-03-27T06:36:33.482Z (about 1 year ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# uFileCache
A minimal static file cache handler for [uWebSocket.js](https://github.com/uNetworking/uWebSockets.js)
> NOTE: Only for small files.
## Installation
Add the following to your `package.json` file:
```json
{
"dependencies": {
"uFileCache": "github:erf/uFileCache"
}
}
```
Then run `npm install`.
## Usage
```javascript
// import the modules
import uWS from 'uWebSockets.js'
import FileCache from 'uFileCache'
const fileCache = new FileCache()
// load files in folder to memory
fileCache.init('public')
// create a new app
const app = uWS.App()
// index.html
app.get('/', (res, req) => fileCache.send('./public/index.html', res))
// static files
app.get('/*', (res, req) => fileCache.send(`./public${req.getUrl()}`, res))
```
## Test
```
node --test --no-warnings=ExperimentalWarning
```