Use multi level paths with one controller but not trigger on static assets #1578
-
Hi, I am learning to work with Ts.ED I am a bit stuck with the following concept. Context: Problem: My controller looks like: @Controller('/')
@UseBefore(ClientGlobalMiddleware)
export class TemplateController {
constructor(
private templateService: TemplateService,
) { }
@Get('/:template/:successPage')
@Get('/:template')
@View("template.hbs")
public async get(
@PathParams('template') template: string,
@PathParams('successPage') successPage: string,
): Promise<any> {
const content = await this.templateService.getContent(template, successPage);
... Just using the one How do I differentiate between path I actually want to respond to and assets that should just be served. So I guess I want to add an ignore list to paths linked to this controller. UPDATE: one of the issues causing the loading of static assets and favicon was that in the html template, those paths didn't start with a forward slash. So they started relatively from the url path. However I still have trouble capturing |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hello @mattiLeBlanc I just released a new version of Ts.ED that let you to change the statics/controllers order. https://tsed.io/docs/serve-files.html#configuration It should solve your issue by adding the Also, you can simplify your Get decorator: @Controller('/')
@UseBefore(ClientGlobalMiddleware)
export class TemplateController {
constructor(
private templateService: TemplateService,
) { }
@Get('/:template/:successPage?')
@View("template.hbs")
public async get(
@PathParams('template') template: string,
@PathParams('successPage') successPage: string,
): Promise<any> {
const content = await this.templateService.getContent(template, successPage);
... Replace all Get() by @get('/:template/:successPage?') See you |
Beta Was this translation helpful? Give feedback.
-
Thank you so much @Romakita . Works like a charm. |
Beta Was this translation helpful? Give feedback.
Hello @mattiLeBlanc
I just released a new version of Ts.ED that let you to change the statics/controllers order. https://tsed.io/docs/serve-files.html#configuration
It should solve your issue by adding the
statics.hook = '$beforeRoutesInit'
options.Also, you can simplify your Get decorator: