nestjs设置静态资源服务器

文件目录

nestjs设置静态资源服务器_第1张图片

main.ts

import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';
import {join} from 'path';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  app.useStaticAssets(join(__dirname, '../public/', 'static'), {
    prefix: '/static/', // 虚拟名称 http://localhost:3010/static/...png
  });
  await app.listen(3010);
}
bootstrap();

app.controller

  @Get()
  getHello(@Res() res: Response) {
    res.sendFile(join(__dirname, '../public/', 'index.html'));
  }//返回html页面
}

你可能感兴趣的:(Node)