TRouter

import { TRouter } from '@appt/api';

A special-type extender to handle routes. Here, we are specifically handling the component to become an express base path router.We love express, but one of the things we miss, it's the capability of easily segment their routes into many different components.

api.router.js
import { Component } from '@appt/core';
import { TRouter } from '@appt/api';
@Component({
extend: TRouter('/api', {
children: ['PrivateRouter', 'PublicRouter']
})
})
export class ApiRouter{}
public.router.js
import { Component } from '@appt/core';
import { TRouter } from '@appt/api';
@Component({
extend: TRouter('/public')
})
export class PublicRouter{}
private.router.js
@Component({
extend: TRouter('/private', {
auth: {
secret: '231edfrw21g34',
ignore: ['favicon.ico', /\/back-/\/]
}
})
})
export class PrivateRouter{}

A few things are going on here. The children: ['PrivateRouter', 'PublicRouter'] will tell ApptJs to look if such components are TRouters. If so, they're gonna assemble their paths and form a base path.

Another thing to pay attention is the auth property:

...
auth: {
secret: '231edfrw21g34',
ignore: ['favicon.ico', /\/back-/\/]
}
...

We are using express-jwt to control our router access. So, if you want to protect some path, just define the JWT secret to decrypt the Bearer Authorization token passed on the request header and, if you want some exception rule to ignore a path, just use the respective property.