diff options
| author | Kagami Sascha Rosylight <saschanaz@outlook.com> | 2023-03-09 18:37:44 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-10 02:37:44 +0900 |
| commit | e0b7633a7adb6f2744e1142637bbbd6ac6624031 (patch) | |
| tree | dab693ed58c315cc0d4ea3ab2348512b72ccba67 /packages/backend/src/server/api/openapi/OpenApiServerService.ts | |
| parent | fix(client): Solve the problem of not automatically jumping to /admin/overvie... (diff) | |
| download | misskey-e0b7633a7adb6f2744e1142637bbbd6ac6624031.tar.gz misskey-e0b7633a7adb6f2744e1142637bbbd6ac6624031.tar.bz2 misskey-e0b7633a7adb6f2744e1142637bbbd6ac6624031.zip | |
enhance(backend): restore OpenAPI endpoints (#10281)
* enhance(backend): restore OpenAPI endpoints
* Update CHANGELOG.md
* version
* set max-age
* update redoc
* follow redoc documentation
---------
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Diffstat (limited to 'packages/backend/src/server/api/openapi/OpenApiServerService.ts')
| -rw-r--r-- | packages/backend/src/server/api/openapi/OpenApiServerService.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/backend/src/server/api/openapi/OpenApiServerService.ts b/packages/backend/src/server/api/openapi/OpenApiServerService.ts new file mode 100644 index 0000000000..e804ba276c --- /dev/null +++ b/packages/backend/src/server/api/openapi/OpenApiServerService.ts @@ -0,0 +1,31 @@ +import { fileURLToPath } from 'node:url'; +import { Inject, Injectable } from '@nestjs/common'; +import type { Config } from '@/config.js'; +import { DI } from '@/di-symbols.js'; +import { bindThis } from '@/decorators.js'; +import { genOpenapiSpec } from './gen-spec.js'; +import type { FastifyInstance, FastifyPluginOptions } from 'fastify'; + +const staticAssets = fileURLToPath(new URL('../../../../assets/', import.meta.url)); + +@Injectable() +export class OpenApiServerService { + constructor( + @Inject(DI.config) + private config: Config, + ) { + } + + @bindThis + public createServer(fastify: FastifyInstance, _options: FastifyPluginOptions, done: (err?: Error) => void) { + fastify.get('/api-doc', async (_request, reply) => { + reply.header('Cache-Control', 'public, max-age=86400'); + return await reply.sendFile('/redoc.html', staticAssets); + }); + fastify.get('/api.json', (_request, reply) => { + reply.header('Cache-Control', 'public, max-age=600'); + reply.send(genOpenapiSpec(this.config)); + }); + done(); + } +} |