0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

Merge pull request #54 from logto-io/gao--fixing-ui-proxy

chore(core): fixing ui proxy `next()` usage
This commit is contained in:
Gao Sun 2021-07-31 16:27:29 +08:00 committed by GitHub
commit 8b6acabe0e

View file

@ -1,5 +1,5 @@
import fs from 'fs';
import { Middleware } from 'koa';
import { MiddlewareType } from 'koa';
import proxy from 'koa-proxies';
import serveStatic from 'koa-static';
import { IRouterParamContext } from 'koa-router';
@ -12,13 +12,15 @@ export default function koaUIProxy<
StateT,
ContextT extends IRouterParamContext,
ResponseBodyT
>(): Middleware<StateT, ContextT, ResponseBodyT> {
const developmentProxy = proxy('*', {
>(): MiddlewareType<StateT, ContextT, ResponseBodyT> {
type Middleware = MiddlewareType<StateT, ContextT, ResponseBodyT>;
const developmentProxy: Middleware = proxy('*', {
target: 'http://localhost:5000',
changeOrigin: true,
logs: true,
});
const staticProxy = serveStatic(PATH_TO_UI_DIST);
const staticProxy: Middleware = serveStatic(PATH_TO_UI_DIST);
return async (context, next) => {
// Route has been handled by one of mounted apps
@ -27,15 +29,13 @@ export default function koaUIProxy<
}
if (!isProduction) {
await developmentProxy(context, next);
return next();
return developmentProxy(context, next);
}
if (!uiDistFiles.some((file) => context.request.path.startsWith(`/${file}`))) {
context.request.path = '/';
}
await staticProxy(context, next);
return next();
return staticProxy(context, next);
};
}