@skweb/fastify
v1.2.2
Published
Fastify runtime adapter for @skweb/framework.
Readme
@skweb/fastify
Fastify runtime adapter for @skweb/framework. Provides the same API surface as @skweb/express (controllers, JWT, ajv validation, response wrapping, permissions), so the same controller code can run on either Express or Fastify.
Installation
npm install @skweb/fastifyUsage
import { WebFramework } from '@skweb/framework'
import { createFastifyApp } from '@skweb/fastify'
const framework = new WebFramework({
runtimeFactory: createFastifyApp,
// ...database / redis / models config
})
const app = framework.createApp()
// Configure JWT (delegates to @skweb/jwt dual-adapter)
app.setJWT('default', {
secret: 'your-secret-key',
algorithms: ['HS256']
})
// Load controllers (object-style route declarations)
await app.loadControllers('./controllers')
// Start server
framework.start(3000)Feature parity with @skweb/express
| Capability | Supported |
|------------|-----------|
| createApp() factory | Yes |
| loadControllers(dir) | Yes |
| startServe(port, hostname?) | Yes |
| Object-style controllers (method/path/jwt/roles/permissions/midwares) | Yes |
| bodySchema / querySchema / paramsSchema (ajv) | Yes |
| setJWT / setJwtHintHeader (via @skweb/jwt) | Yes |
| setUserAuth / setVerifyAuth / verifyRoles / verifyPermissions | Yes |
| sendOk / sendError / response wrapping | Yes |
| setSendOkFunc / setSendErrorFunc / setRespCodeKey / setRespMsgKey / setOkCode / setOkMessage | Yes |
Differences from @skweb/express
- JWT is delegated to
@skweb/jwt'screateFastifyPreHandler()(Express uses its ownappjwt.ts) - Express-style
(req, res, next)middlewares in controllermidwaresare auto-adapted to FastifypreHandler - Settings API (
app.get/app.set) is emulated via an internalMap(noexpress()app)
License
MIT
