1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-28 17:55:15 +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:
Gastón Fournier 2025-05-28 19:14:55 +02:00 committed by GitHub
parent 707c2de9b1
commit 241b7e8165
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 6 additions and 21 deletions

View File

@ -9,7 +9,6 @@
!LICENSE !LICENSE
!README.md !README.md
!frontend !frontend
!openapi-static
frontend/node_modules frontend/node_modules
!.yarn/** !.yarn/**
!.yarnrc.yml !.yarnrc.yml

View File

Before

Width:  |  Height:  |  Size: 860 B

After

Width:  |  Height:  |  Size: 860 B

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -13,7 +13,6 @@
], ],
"files": [ "files": [
"dist", "dist",
"openapi-static",
"frontend/build", "frontend/build",
"frontend/build/*", "frontend/build/*",
"frontend/build/**/*", "frontend/build/**/*",
@ -50,7 +49,7 @@
"db-migrate": "db-migrate --migrations-dir ./src/migrations", "db-migrate": "db-migrate --migrations-dir ./src/migrations",
"lint": "biome check .", "lint": "biome check .",
"lint:fix": "biome check . --write", "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", "build:watch": "tsc -w",
"prepare": "husky && yarn --cwd ./frontend install && if [ ! -d ./dist ]; then yarn build; fi", "prepare": "husky && yarn --cwd ./frontend install && if [ ! -d ./dist ]; then yarn build; fi",
"test": "PORT=4243 vitest run", "test": "PORT=4243 vitest run",

View File

@ -1,10 +1,5 @@
import openapi, { type IExpressOpenApi } from '@wesleytodd/openapi'; import openapi, { type IExpressOpenApi } from '@wesleytodd/openapi';
import { import type { Express, RequestHandler, Response } from 'express';
type Express,
type RequestHandler,
type Response,
static as expressStatic,
} from 'express';
import type { IUnleashConfig } from '../types/option.js'; import type { IUnleashConfig } from '../types/option.js';
import { import {
createOpenApiSchema, createOpenApiSchema,
@ -44,14 +39,15 @@ export class OpenApiService {
validPath(op: ApiOperation): RequestHandler { validPath(op: ApiOperation): RequestHandler {
const { beta, enterpriseOnly, ...rest } = op; const { beta, enterpriseOnly, ...rest } = op;
const { baseUriPath = '' } = this.config.server ?? {};
const openapiStaticAssets = `${baseUriPath}/openapi-static`;
const betaBadge = beta const betaBadge = beta
? `![Beta](${this.docsStaticsPath()}/Beta.svg) This is a beta endpoint and it may change or be removed in the future. ? `![Beta](${openapiStaticAssets}/Beta.svg) This is a beta endpoint and it may change or be removed in the future.
` `
: ''; : '';
const enterpriseBadge = enterpriseOnly const enterpriseBadge = enterpriseOnly
? `![Unleash Enterprise](${this.docsStaticsPath()}/Enterprise.svg) **Enterprise feature** ? `![Unleash Enterprise](${openapiStaticAssets}/Enterprise.svg) **Enterprise feature**
` `
: ''; : '';
@ -68,15 +64,6 @@ export class OpenApiService {
useDocs(app: Express): void { useDocs(app: Express): void {
app.use(this.api); app.use(this.api);
app.use(this.docsPath(), this.api.swaggerui()); 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 { docsPath(): string {