mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +02:00
chore: simplify serving of static openapi assets (#10046)
Use existing public folder from frontend to serve opeanapi static assets. We also benefit from frontend image optimizations
This commit is contained in:
parent
707c2de9b1
commit
241b7e8165
@ -9,7 +9,6 @@
|
||||
!LICENSE
|
||||
!README.md
|
||||
!frontend
|
||||
!openapi-static
|
||||
frontend/node_modules
|
||||
!.yarn/**
|
||||
!.yarnrc.yml
|
||||
|
Before Width: | Height: | Size: 860 B After Width: | Height: | Size: 860 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@ -13,7 +13,6 @@
|
||||
],
|
||||
"files": [
|
||||
"dist",
|
||||
"openapi-static",
|
||||
"frontend/build",
|
||||
"frontend/build/*",
|
||||
"frontend/build/**/*",
|
||||
@ -50,7 +49,7 @@
|
||||
"db-migrate": "db-migrate --migrations-dir ./src/migrations",
|
||||
"lint": "biome check .",
|
||||
"lint:fix": "biome check . --write",
|
||||
"local:package": "del-cli --force build && mkdir build && cp -r dist openapi-static CHANGELOG.md LICENSE README.md package.json build",
|
||||
"local:package": "del-cli --force build && mkdir build && cp -r dist CHANGELOG.md LICENSE README.md package.json build",
|
||||
"build:watch": "tsc -w",
|
||||
"prepare": "husky && yarn --cwd ./frontend install && if [ ! -d ./dist ]; then yarn build; fi",
|
||||
"test": "PORT=4243 vitest run",
|
||||
|
@ -1,10 +1,5 @@
|
||||
import openapi, { type IExpressOpenApi } from '@wesleytodd/openapi';
|
||||
import {
|
||||
type Express,
|
||||
type RequestHandler,
|
||||
type Response,
|
||||
static as expressStatic,
|
||||
} from 'express';
|
||||
import type { Express, RequestHandler, Response } from 'express';
|
||||
import type { IUnleashConfig } from '../types/option.js';
|
||||
import {
|
||||
createOpenApiSchema,
|
||||
@ -44,14 +39,15 @@ export class OpenApiService {
|
||||
|
||||
validPath(op: ApiOperation): RequestHandler {
|
||||
const { beta, enterpriseOnly, ...rest } = op;
|
||||
|
||||
const { baseUriPath = '' } = this.config.server ?? {};
|
||||
const openapiStaticAssets = `${baseUriPath}/openapi-static`;
|
||||
const betaBadge = beta
|
||||
? `}/Beta.svg) This is a beta endpoint and it may change or be removed in the future.
|
||||
? ` This is a beta endpoint and it may change or be removed in the future.
|
||||
|
||||
`
|
||||
: '';
|
||||
const enterpriseBadge = enterpriseOnly
|
||||
? `}/Enterprise.svg) **Enterprise feature**
|
||||
? ` **Enterprise feature**
|
||||
|
||||
`
|
||||
: '';
|
||||
@ -68,15 +64,6 @@ export class OpenApiService {
|
||||
useDocs(app: Express): void {
|
||||
app.use(this.api);
|
||||
app.use(this.docsPath(), this.api.swaggerui());
|
||||
app.use(
|
||||
this.docsStaticsPath(),
|
||||
expressStatic('openapi-static', { index: false }),
|
||||
);
|
||||
}
|
||||
|
||||
docsStaticsPath(): string {
|
||||
const { baseUriPath = '' } = this.config.server ?? {};
|
||||
return `${baseUriPath}/docs/static`;
|
||||
}
|
||||
|
||||
docsPath(): string {
|
||||
|
Loading…
Reference in New Issue
Block a user