Skip to content

Commit

Permalink
✔ Exclude Exact Path With Prefix ~
Browse files Browse the repository at this point in the history
  • Loading branch information
bifeldy committed May 9, 2023
1 parent 5c6a97f commit f069b56
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/fansubid/browser/ngsw.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"configVersion": 1,
"timestamp": 1683654147098,
"timestamp": 1683658624560,
"index": "/index.html",
"assetGroups": [
{
Expand Down
2 changes: 1 addition & 1 deletion dist/fansubid/server/main.js

Large diffs are not rendered by default.

54 changes: 41 additions & 13 deletions src/api/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,31 +294,58 @@ import { UserService } from './repository/user.service';
})
export class AppModule {

// Exclude route referring exact route path
// https://stackoverflow.com/questions/61152975/nestjs-middleware-for-all-routes-except-auth
configure(mc: MiddlewareConsumer) {
mc.apply(UrlXmlMiddleware).forRoutes({ path: '*', method: RequestMethod.ALL });

mc.apply(UrlXmlMiddleware).forRoutes(
{ path: '*', method: RequestMethod.ALL }
);

mc.apply(ApiKeyMiddleware).exclude(
{ path: '/api/discord-verifikasi', method: RequestMethod.GET },
{ path: '/api/google-verifikasi', method: RequestMethod.GET },
{ path: '/api/aktivasi', method: RequestMethod.GET },
{ path: '/api/verify-sosmed', method: RequestMethod.GET }
).forRoutes({ path: '*', method: RequestMethod.ALL });
).forRoutes(
{ path: '*', method: RequestMethod.ALL }
);

mc.apply(BannedMiddleware).exclude(
{ path: '/api/aktivasi', method: RequestMethod.GET },
{ path: '/api/verify-sosmed', method: RequestMethod.GET },
{ path: '/api/login', method: RequestMethod.POST },
{ path: '/api/register', method: RequestMethod.POST },
{ path: '/api/lost-account-*', method: RequestMethod.POST }
).forRoutes({ path: '*', method: RequestMethod.ALL });
mc.apply(LoginMiddleware).forRoutes({ path: '/api/login', method: RequestMethod.POST });
mc.apply(RegisterMiddleware).forRoutes({ path: '/api/register', method: RequestMethod.POST });
mc.apply(LogoutMiddleware).forRoutes({ path: '/api/logout', method: RequestMethod.DELETE });
mc.apply(CacheMiddleware).forRoutes({ path: '*', method: RequestMethod.GET });
).forRoutes(
{ path: '*', method: RequestMethod.ALL }
);

mc.apply(LoginMiddleware).forRoutes(
{ path: '/login', method: RequestMethod.POST }
);

mc.apply(RegisterMiddleware).forRoutes(
{ path: '/register', method: RequestMethod.POST }
);

mc.apply(LogoutMiddleware).forRoutes(
{ path: '/logout', method: RequestMethod.DELETE }
);

mc.apply(CacheMiddleware).forRoutes(
{ path: '*', method: RequestMethod.GET }
);

mc.apply(throttle(CONSTANTS.attachmentSpeedLimiterBps)).forRoutes(
{ path: '/api/attachment', method: RequestMethod.GET },
{ path: '/api/ddl-part', method: RequestMethod.GET },
{ path: '/api/ddl-seek', method: RequestMethod.GET }
{ path: '/attachment', method: RequestMethod.GET },
{ path: '/ddl-part', method: RequestMethod.GET },
{ path: '/ddl-seek', method: RequestMethod.GET }
);

mc.apply(
uploadx.upload({
path: '/api/attachment',
path: '/attachment',
allowMIME: CONSTANTS.fileTypeAttachmentAllowed,
directory: environment.uploadFolder,
maxUploadSize: CONSTANTS.fileSizeAttachmentTotalLimit,
Expand All @@ -332,9 +359,10 @@ export class AppModule {
}
})
).forRoutes(
{ path: '/api/attachment', method: RequestMethod.POST },
{ path: '/api/attachment', method: RequestMethod.PUT }
{ path: '/attachment', method: RequestMethod.POST },
{ path: '/attachment', method: RequestMethod.PUT }
);

}

}

0 comments on commit f069b56

Please sign in to comment.