init
This commit is contained in:
21
backend/src/middleware/storage.ts
Normal file
21
backend/src/middleware/storage.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import fp from 'fastify-plugin'
|
||||
import type { FastifyPluginAsync } from 'fastify'
|
||||
import { SQLiteAdapter } from '../adapters/sqlite.ts'
|
||||
import type { StorageAdapter } from '../types.ts'
|
||||
|
||||
declare module 'fastify' {
|
||||
interface FastifyRequest {
|
||||
storage: StorageAdapter
|
||||
}
|
||||
}
|
||||
|
||||
const adapter: StorageAdapter = new SQLiteAdapter()
|
||||
|
||||
const plugin: FastifyPluginAsync = async (app) => {
|
||||
app.decorateRequest('storage', null)
|
||||
app.addHook('onRequest', async (req) => {
|
||||
req.storage = adapter
|
||||
})
|
||||
}
|
||||
|
||||
export const storageMiddleware = fp(plugin)
|
||||
Reference in New Issue
Block a user