Amit Kumar
Amit Kumar

Reputation: 660

How to serve multiple SPA in nestjs using fastify

The configuration mentioned below works absolutely fine with express but it is giving error when used with fastify.

export const serveStaticModule_one: ServeStaticModuleOptions = {
    rootPath: join(process.cwd(), 'one')
};

export const serveStaticModule_two: ServeStaticModuleOptions = {
    rootPath: join(process.cwd(), 'two'),
    renderPath: '/two'
};

export const serveStaticModule_three: ServeStaticModuleOptions = {
    rootPath: join(process.cwd(), 'three'),
    renderPath: '/three',
    serveStaticOptions: {
        index: 'client.html'
    }
};
package used version
@nestjs/platform-fastify 8.2.3
@nestjs/serve-static 2.2.2
fastify-static 4.5.0

Exact error is The decorator 'sendFile' has already been added
I tried passing these object to single ServeStaticModule.forRoot() and to multiple, but none of them works.

Upvotes: 0

Views: 1514

Answers (1)

Amit Kumar
Amit Kumar

Reputation: 660

I found the solution by creating new type.

type FastifyServeStaticModuleOptions = _ServeStaticModuleOptions & {
    serveStaticOptions: {
        decorateReply: boolean;
    };
};

then i created object like this:

export const serveStaticModule_one: FastifyServeStaticModuleOptions = {
    rootPath: join(process.cwd(), 'one'),
    serveStaticOptions: {
        decorateReply: false
    }
};

It worked perfectly after this.

Upvotes: 0

Related Questions