samchon / nestia-helper

NestJS helper with Type level
MIT License
34 stars 3 forks source link

Using TypedRoute on html rendered route doesn't work #33

Open ilterugur opened 2 years ago

ilterugur commented 2 years ago

package.json:

"express-handlebars": "^6.0.6",
"nestia-helper": "^3.0.9",

main.ts:

import { engine as handlebarsEngine } from 'express-handlebars';

.....
.....

const viewEngineTemplatesRoot = join(rootDirName, 'views');

app.engine(
    'handlebars',
    handlebarsEngine({
        defaultLayout: false,
    }),
);
app.setViewEngine('handlebars');
app.setBaseViewsDir(viewEngineTemplatesRoot);

app.controller.ts:

import { Controller, Render } from '@nestjs/common';
import { TypedRoute } from 'nestia-helper';
import { AppService } from './app.service';

@Controller()
export class AppController {
    constructor(private readonly appService: AppService) {}

    @TypedRoute.Get()
    @Render('index.handlebars')
    root() {
        const message = this.appService.getHello();
        return { message };
    }
}

Error: TypeError: Cannot create property '_locals' on string '{"message":"Hello World!"}'