import {NestExpressApplication} from "@nestjs/platform-express";
import {join} from "path";
// main.ts
async function bootstrap() {
// 创建实例
const app:NestExpressApplication = await NestFactory.create(AppModule);
//方式一
app.useStaticAssets(join(__dirname, '..', 'public')); //配置静态资源目录
await app.listen(3000);
}
bootstrap().then(() => console.log('Server started'));import {NestExpressApplication} from "@nestjs/platform-express";
import {join} from "path";
// main.ts
async function bootstrap() {
// 创建实例
const app:NestExpressApplication = await NestFactory.create(AppModule);
//方式二
app.useStaticAssets(join(__dirname, '..', 'public')), { // 配置虚拟目录,比如我们想通过 http://localhost:3000/static/1.jpg 来访问public目录里面的文件
prefix: '/static/', // 设置虚拟路径
});
await app.listen(3000);
}
bootstrap().then(() => console.log('Server started'));www.haizhuan.tk