node请求页面时自动下载

news/2025/2/27 12:20:31

问题如下,这里浏览器访问接口会直接下载

const router = require('express').Router();
const fs = require('fs');

router.get('/index.html',(req,res)=>{
	fs.readFile('./views/cookie.html','utf8',(err,data)=>{
		if(err) res.send('error');
		else res.send(data);
	});
});
module.exports = router;

修正、将res.send改为res.end

const router = require('express').Router();
const fs = require('fs');

router.get('/index.html',(req,res)=>{
	fs.readFile('./views/cookie.html','utf8',(err,data)=>{
		if(err) res.send('error');
		else res.send(data);
	});
});
module.exports = router;

问题解决


http://www.niftyadmin.cn/n/4611443.html

相关文章

Android中EditText显示明文与密码的两种方式

效果图如下所述&#xff1a; <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android" xmlns:tools"http://schemas.android.com/tools" android:layout_width&qu…

context must be a dict rather解决

原来的代码 def depart_edit(request, nid):# 修改部门# 根据获取到的nid查询数据库row models.Department.objects.filter(idnid).first()# 转发数据row到depart_edit.htmlreturn render(request, depart_edit.html, row)最终发现问题render()第三个参数应该是对象形式 def…

OS层面删除数据文件后的恢复方式(LINUX):

此次删除数据文件后&#xff0c;请不要重启数据库或者关闭数据库&#xff0c;可直接在线恢复。测试方式&#xff1a;先从数据库中查看数据库数据文件的文件号及路径&#xff1a; SQL> select FILE# ,name from v$datafile;FILE# NAME ---------- -----------------------…

pyside2____1.安装和案列

安装 pip install pyside2 -i https://pypi.douban.com/simple/ 代码main.py from PySide2.QtWidgets import QApplication, QMainWindow, QPlainTextEdit, QPushButtonapp QApplication() # 总程序 window QMainWindow() # 主窗口对象 window.resize(500, 400) window.m…

Could not autowire.No beans of ‘userMapper‘ type found.

这里并没有错误&#xff0c;但是IDEA报红 package com.example.demo.mapper;import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.t…

腾讯iphone面试题(转)

1Objective&#xff0d;C内部的实现2CALayer和View的关系3 http协议&#xff0c;tcp/ip4 UITableView的那些元素是可以自定义的&#xff1f;5 c语言的&#xff0c;定义变量&#xff0c;比如int&#xff0c;在什么情况下&#xff0c;其最大值是不同的6 比较32位平台和64位平台不…

spring boot jwt完整过程

首先源码https://gitee.com/mobile191llx/spring-boot-jwt.git 接着项目目录结构 项目开始 1.新建项目名称为demo、选择maven什么都不要勾选 2.依赖pom.xml <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache…

PGA结构

当客户端向服务器发送连接请求&#xff0c;服务器监听到客户端的请求&#xff0c;在专用服务器模式下&#xff0c;会在服务器端衍生一个server process来代理客户的请求&#xff0c;server process进而向实例发起连接&#xff0c;创建会话&#xff0c;而PGA就为server process所…