#serve-static being overwritten by a catch all

3 messages · Page 1 of 1 (latest)

grave shale
#

I'm trying to serve static files in a directory named "public" at the root of the project,

@Module({
  imports: [
    ServeStaticModule.forRoot({
      rootPath: join(__dirname, '..', 'public')
    }),
    TypeOrmModule.forRoot(ormConfig),
    TypeOrmModule.forFeature([Page, Setting]),
    PagesModule,
    SettingsModule
  ],
  controllers: [AppController, PublicPagesController, AdminController],
  providers: [AppService, PublicPagesService, SettingsService]
})
export class AppModule {}

code for the catchall

@Controller()
export class PublicPagesController {
  constructor (private readonly publicPagesService: PublicPagesService) {}

  @Get('*')
  async catchAll (@Req() request: Request): Promise<string> {

the catch all is in the PublicPagesController, since I'm importing the ServeStatic at the top, if I had a "test.png" in the "public" directory, I should see the file if I accessed "http://localhost:3000/test.png", but when I access it I am hitting the catchall in the controller. Is there any reason this is happening?

cinder fjordBOT
#

Please format your question or answer with Markdown formatting.
It leads to better readability and an easier time to spot problems.
For code blocks, you can wrap your block with three back ticks before and after the block, and after the first three back ticks you can add a language (like ts) to add syntax highlighting.
e.g.

```ts
@Injectable()
export class MySuperAwesomeService {
constructor(@Inject('InjectionToken') private readonly dep: SomeDependency) {}

getRandomNumber(): number {
return Math.round(Math.random() * 1000);
}
}
```

Becomes :point_down:

@Injectable()
export class MySuperAwesomeService {
  constructor(@Inject('InjectionToken') private readonly dep: SomeDependency) {}

  getRandomNumber(): number {
    return Math.round(Math.random() * 1000);
  }
}
grave shale
#

I've fixed it and added some more code