Skip to content

Commit

Permalink
Refact routes, add feat
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoncool committed Nov 22, 2024
1 parent 65da9a5 commit e7ca14f
Show file tree
Hide file tree
Showing 2 changed files with 241 additions and 212 deletions.
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {AppEnv} from './const';
import {registry} from './registry';
import {getRoutes} from './routes';
import {setRegistryToContext} from './components/app-context';
import {isEnabledFeature} from './components/features';
import {objectKeys} from './utils/utility-types';

setRegistryToContext(nodekit, registry);
registerAppPlugins();
Expand Down Expand Up @@ -57,9 +59,11 @@ nodekit.config.appFinalErrorHandler = finalRequestHandler;
const extendedRoutes = getRoutes(nodekit, {beforeAuth, afterAuth});

const routes: AppRoutes = {};
Object.keys(extendedRoutes).forEach((key) => {
const {route, ...params} = extendedRoutes[key];
routes[route] = params;
objectKeys(extendedRoutes).forEach((key) => {
const {route, feat, ...params} = extendedRoutes[key];
if (!Array.isArray(feat) || feat.every((flag) => isEnabledFeature(nodekit.ctx, flag))) {
routes[route] = params;
}
});

const app = new ExpressKit(nodekit, routes);
Expand Down
Loading

0 comments on commit e7ca14f

Please sign in to comment.