mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -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:
commit
8b6acabe0e
1 changed files with 8 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { Middleware } from 'koa';
|
import { MiddlewareType } from 'koa';
|
||||||
import proxy from 'koa-proxies';
|
import proxy from 'koa-proxies';
|
||||||
import serveStatic from 'koa-static';
|
import serveStatic from 'koa-static';
|
||||||
import { IRouterParamContext } from 'koa-router';
|
import { IRouterParamContext } from 'koa-router';
|
||||||
|
@ -12,13 +12,15 @@ export default function koaUIProxy<
|
||||||
StateT,
|
StateT,
|
||||||
ContextT extends IRouterParamContext,
|
ContextT extends IRouterParamContext,
|
||||||
ResponseBodyT
|
ResponseBodyT
|
||||||
>(): Middleware<StateT, ContextT, ResponseBodyT> {
|
>(): MiddlewareType<StateT, ContextT, ResponseBodyT> {
|
||||||
const developmentProxy = proxy('*', {
|
type Middleware = MiddlewareType<StateT, ContextT, ResponseBodyT>;
|
||||||
|
|
||||||
|
const developmentProxy: Middleware = proxy('*', {
|
||||||
target: 'http://localhost:5000',
|
target: 'http://localhost:5000',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
logs: true,
|
logs: true,
|
||||||
});
|
});
|
||||||
const staticProxy = serveStatic(PATH_TO_UI_DIST);
|
const staticProxy: Middleware = serveStatic(PATH_TO_UI_DIST);
|
||||||
|
|
||||||
return async (context, next) => {
|
return async (context, next) => {
|
||||||
// Route has been handled by one of mounted apps
|
// Route has been handled by one of mounted apps
|
||||||
|
@ -27,15 +29,13 @@ export default function koaUIProxy<
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isProduction) {
|
if (!isProduction) {
|
||||||
await developmentProxy(context, next);
|
return developmentProxy(context, next);
|
||||||
return next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!uiDistFiles.some((file) => context.request.path.startsWith(`/${file}`))) {
|
if (!uiDistFiles.some((file) => context.request.path.startsWith(`/${file}`))) {
|
||||||
context.request.path = '/';
|
context.request.path = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
await staticProxy(context, next);
|
return staticProxy(context, next);
|
||||||
return next();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue