Nestjs 设置静态文件,public
Docs: https://docs.nestjs.com/techniques/mvc
新版本需要设置为NestExpressApplication
import { NestExpressApplication } from '@nestjs/platform-express';
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.setBaseViewsDir(join(__dirname, '..', 'views'));
...
main.js
import {
NestFactory
} from '@nestjs/core';
import {
AppModule
} from './app.module';
import { join } from 'path'
async function bootstrap() {
const app = await NestFactory.create(AppModule);
// app.useStaticAssets(join(__dirname, '..', 'public')) // http://localhost:5000/xxx.txt
// app.useStaticAssets('public') 跟上面一样
app.useStaticAssets(join(__dirname, '..', 'public'),{
prefix: '/static/', 设置虚拟路径
}) // http://localhost:5000/static/xxx.txt
await app.listen(5000);
}
bootstrap();
加载静态页面
yarn add ejs
import {
NestFactory
} from '@nestjs/core'
import {
AppModule
} from './app.module'
import {
join
} from 'path'
import {
renderFile
} from 'ejs'
const l = console.log
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useStaticAssets(join(__dirname, '..', 'public'), {
prefix: '/static/'
})
app.setBaseViewsDir(join(__dirname, '..', 'views')) // 放视图的文件
app.engine('html', renderFile);
app.set('view engine', 'html');
await app.listen(5000)
}
bootstrap();
@Get()
@Render('index') // 使用render渲染 /views/index.hmtl 文件
root() { }
sendFile
@Get()
root(@Response() res): any {
res.sendFile(join(__dirname, '../view/', 'index.html'))
// return this.appService.root();
}
Nestjs 设置静态文件,public的更多相关文章
- node.js 设置静态文件托管
1.在app.js文件中设置静态文件托管 /*应用程序入口文件*/ /*加载express模块*/ var express = require('express'); /*加载模板处理模块*/ var ...
- django 设置静态文件,static
django 设置静态文件,static 一.搜集静态文件 1.1 命令行查看 collectstatic guoguos-MacBook-Pro:mysite guoguo$ python mana ...
- django 设置静态文件,static 链接
这篇文章讲的django 静态static 文件设置,还可以,供参考 http://blog.csdn.net/sinat_21302587/article/details/74059078
- Apache设置静态文件的失效时间
步骤1:启用expires模块 [root@zlinux logs]# vim httpd.conf LoadModule expires_module modules/mod_expires.so ...
- Django设置中文,和时区、静态文件指向
#========================================================== # 设置时区 注意注释上面的:LANGUAGE_CODE.TIME_ZONE.U ...
- 在ashx和静态文件中使用Session
在ashx页面中如果想使用可读可写的Session,必须要实现一个接口“IRequiresSessionState”,在这个接口中没有定义任何方法,这样的接口被称为“标识接口”. public int ...
- (5)ASP.NET Core 中的静态文件
1.前言 当我们创建Core项目的时候,Web根目录下会有个wwwroot文件目录,wwwroot文件目录里面默认有HTML.CSS.IMG.JavaScript等文件,而这些文件都是Core提供给客 ...
- 45. Express 框架 静态文件处理
转自:http://www.runoob.com/nodejs/nodejs-express-framework.html Express 提供了内置的中间件 express.static 来设置静态 ...
- 使用node建立本地服务器访问静态文件
最终目录结构 demo │ node_modules └───public │ │ index.html │ │ index.css │ └───index.js └───server.js 一.使用 ...
随机推荐
- 使用C#版Tesseract库
上一篇介绍了Tesseract库的使用(OCR库Tesseract初探),文末提到了Tesseract是用c/c++开发的,也有C#的开源版本,本篇介绍一下如何使用C#版的Tesseract. C#版 ...
- C#退出程序,退出任务管理器
//窗体关闭之前 this.FormClosing += (s, r) => { System.Environment.Exit(0); }; //窗体关闭 this.Closed += (s, ...
- C++中的三种继承关系
C++中的三种继承关系 先看类中声明成员时的三种访问权限 public : 可以被任意实体访问 protected : 只允许子类及本类的成员函数访问 private : 只允许本类的成员函数访问 在 ...
- 20151224今天发现到的两篇关于CSS架构、可复用可维护CSS和CSS学习提升能有改变思想观念意识的文章 分别是CSS架构目标和说说CSS学习中的瓶颈
多讲一个,CSS全称是什么?CSS全称为Cascading Style Sheets,中文翻译为“层叠样式表”,简称CSS样式表又被我们称为CSS样式,CSS样式又被作为一种能制作出各种样式网页的技术 ...
- 系统管理员需知的 16 个 iptables 使用技巧
现代 Linux 内核带有一个叫 Netfilter[1] 的数据包过滤框架.Netfilter 提供了允许.丢弃以及修改等操作来控制进出系统的流量数据包.基于 Netfilter 框架的用户层命令行 ...
- Kettle实现数据抽取、转换、装入和加载数据-数据转移ETL工具
原文地址:http://www.xue51.com/soft/5341.html Kettle是来自国外的一款开源的ETL工具,纯java编写,可以在Window.Linux.Unix上运行,绿色无需 ...
- Effective Java 第三版——69. 仅在发生异常的条件下使用异常
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
- 国外优秀C/C++网站
1.https://en.cppreference.com/w/ 2.https://www.geeksforgeeks.org/ 3.https://www.tutorialspoint.com/c ...
- Analyzing the Go runtime scheduler from source code perspective
http://www.cs.columbia.edu/~aho/cs6998/reports/12-12-11_DeshpandeSponslerWeiss_GO.pdf http://www.cs. ...
- Linux 常见操作
grep -nr SEARCHTERM file1 file2 ...https://www.linuxnix.com/grep-command-usage-linux/ https://www.li ...