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 一.使用 ...
随机推荐
- 说说GIL
上一篇:线程深入篇引入 Code:https://github.com/lotapp/BaseCode/tree/master/python/5.concurrent/Thread/3.GIL 说说G ...
- MySQL中exists和in的区别及使用场景
exists和in的使用方式: 1 #对B查询涉及id,使用索引,故B表效率高,可用大表 -->外小内大 1 select * from A where exists (select * fro ...
- centos下安装wireshark 抓包
centos下安装wireshark相当简单.两条命令就够了.这里.主要是记录写使用方面的东西 安装:1.yum install wireshark.注意这样并无法使用wireshark命令和图形界面 ...
- opencv+python-图片文本倾斜校正
# -*- coding: UTF-8 -*- import numpy as np import cv2 ## 图片旋转 def rotate_bound(image, angle): #获取宽高 ...
- html5学习笔记3——高级特性
一:Web存储 数据以 键/值 对存在, web网页的数据只允许该网页访问使用. web存储有两种: localStorage - 没有时间限制的数据存储,存于浏览器缓存 sessionStorage ...
- 在 CentOS 7上Virtualbox+phpVirtualBox完整虚拟化环境部署
一.phpVirtualBox简介 VirtualBox是一套为不同操作系统而设的 x86 虚拟化产品.它是一个机器/硬件的虚拟化产品,功能上与 VMware Server.Parallel ...
- Pilosa文档翻译(一)导言、安装
目录 导言 安装 安装在MacOS 使用HomeBrew 下载二进制文件 从源码构建 使用Docker 安装在Linux 下载二进制文件 从源码构建 使用Docker 接下来是什么? 导言 原文地址 ...
- Python 能做什么?
Python 能做什么? Python具有简单.易学.免费.开源.可移植.可扩展.可嵌入.面向对象等优点,我所关注的是网络爬虫方面,2018即将到来,我准备步入python的世界. Hello,wor ...
- springBoot于tomcat7搭建websocket服务
最近在项目中需要服务端进行推送服务,于是决定使用webSocket进行双向通讯.刚开始觉得应该没问题,参考网上的博客进行开发配置.我们的开发环境使用的是springBoot.tomcat7.servl ...
- 关于VMware Linux 虚拟机忘记root 密码找回
因为昨天新安装过虚拟机设置了新的密码,再加上我好长时间没有用自己旧的虚拟机,导致忘记了密码,原来虽然知道在单用模式下,找回密码,但是确实是自己从来都没有做过,还好我们组大手飞翔哥告诉了我,怎么找回ro ...