https://github.com/jwebcoder/mith_static
Serve static files under Mith framework
https://github.com/jwebcoder/mith_static
Last synced: 11 months ago
JSON representation
Serve static files under Mith framework
- Host: GitHub
- URL: https://github.com/jwebcoder/mith_static
- Owner: JWebCoder
- License: mit
- Created: 2020-06-10T22:18:53.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-19T22:07:10.000Z (almost 6 years ago)
- Last Synced: 2025-02-05T08:08:32.277Z (over 1 year ago)
- Language: TypeScript
- Homepage: https://doc.deno.land/https/deno.land/x/mith_static/mod.ts
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Mith_static

[](https://doc.deno.land/https/deno.land/x/mith_static/mod.ts)
Serve static files under [Mith framework](https://github.com/JWebCoder/mith)
## Usage
**Basic integration**
```typescript
import { Mith } from 'https://deno.land/x/mith@v0.7.0/mod.ts'
import { serverStatic } from 'https://deno.land/x/mith_static@v0.0.1/mod.ts'
const { env } = Deno
const app = new Mith()
app.use(serveStatic(resolve(Deno.cwd(), 'static'), '/static', {
maxage: 120,
}))
app.use((req, res, next) => {
if (!req.requestHandled) {
return next({status: 404, message:'not found'})
}
next()
})
app.error(
(req: Request, res: Response, next: NextFunction) => {
if (res.error) {
res.status = res.error.status || 500
res.body = res.error.message
}
next()
}
)
const PORT = Number(env.get('PORT')) || 8000
app.listen({ port: PORT})
console.log('listening on', PORT)
```
Right now I'm still working on the documentation, so you can check the **example** folder for full usage examples