forked from mirrors/misskey
fix(backend): /api-doc にアクセスできない問題を修正 (#17267)
* Initial plan * fix: fix /api-doc returning 404 after backend minification (#17266) Agent-Logs-Url: https://github.com/misskey-dev/misskey/sessions/8d7d0585-55da-412f-a8ee-dde1b6565026 Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com> * enhance: API DocのHTMLをJSXで生成するように * Update Changelog * chore: remove unused imports [ci skip] --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com> Co-authored-by: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com>
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
-
|
-
|
||||||
|
|
||||||
### Server
|
### Server
|
||||||
-
|
- Fix: `/api-doc` にアクセスできない問題を修正
|
||||||
|
|
||||||
|
|
||||||
## 2026.3.2
|
## 2026.3.2
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Misskey API</title>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script
|
|
||||||
id="api-reference"
|
|
||||||
data-url="/api.json"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.4 KiB |
@@ -3,16 +3,14 @@
|
|||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import type { Config } from '@/config.js';
|
import type { Config } from '@/config.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { genOpenapiSpec } from './gen-spec.js';
|
import { genOpenapiSpec } from './gen-spec.js';
|
||||||
|
import { ApiDocPage } from './api-doc.js';
|
||||||
import type { FastifyInstance, FastifyPluginOptions } from 'fastify';
|
import type { FastifyInstance, FastifyPluginOptions } from 'fastify';
|
||||||
|
|
||||||
const staticAssets = fileURLToPath(new URL('../../../../assets/', import.meta.url));
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class OpenApiServerService {
|
export class OpenApiServerService {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -25,7 +23,8 @@ export class OpenApiServerService {
|
|||||||
public createServer(fastify: FastifyInstance, _options: FastifyPluginOptions, done: (err?: Error) => void) {
|
public createServer(fastify: FastifyInstance, _options: FastifyPluginOptions, done: (err?: Error) => void) {
|
||||||
fastify.get('/api-doc', async (_request, reply) => {
|
fastify.get('/api-doc', async (_request, reply) => {
|
||||||
reply.header('Cache-Control', 'public, max-age=86400');
|
reply.header('Cache-Control', 'public, max-age=86400');
|
||||||
return await reply.sendFile('/api-doc.html', staticAssets);
|
reply.type('text/html; charset=utf-8');
|
||||||
|
reply.send(await ApiDocPage());
|
||||||
});
|
});
|
||||||
fastify.get('/api.json', (_request, reply) => {
|
fastify.get('/api.json', (_request, reply) => {
|
||||||
reply.header('Cache-Control', 'public, max-age=600');
|
reply.header('Cache-Control', 'public, max-age=600');
|
||||||
|
|||||||
26
packages/backend/src/server/api/openapi/api-doc.tsx
Normal file
26
packages/backend/src/server/api/openapi/api-doc.tsx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function ApiDocPage() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{'<!DOCTYPE html>'}
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>Misskey API</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<style>
|
||||||
|
{`body { margin: 0; padding: 0; }`}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script id="api-reference" data-url="/api.json"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user