nestJS前端项目包部署过程

新建nestJS项目

  • main.ts文件
    • 静态资源目录放置在public文件下
import { NestExpressApplication } from '@nestjs/platform-express';
import * as path from 'path';

const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    logger: true,
  });
  app.useStaticAssets(path.join(__dirname, '..', 'public'));
  app.setBaseViewsDir(path.join(__dirname, '..', 'views'));
  app.setViewEngine('hbs');
  // 设置统一的接口前缀
  app.setGlobalPrefix('/react-ant-admin');
  • app.controller.ts文件
import { Response } from 'express';
import * as path from 'path';

  getHello(@Res() res: Response): any {
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    res.sendFile(
      path.join(__dirname, '../public/react-ant-admin', 'index.html'),
    );
  }
}

静态资源放置

在这里插入图片描述

项目运行

  • 浏览器输入:http://localhost:3000/react-ant-admin/
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值