小编Rcr*_*rab的帖子

快速提供静态文件:发送标头后无法设置标头

我正在使用express.static内置的中间件函数来提供静态文件,但是控制台会打印错误:发送后无法设置标头

这是我的代码,我不知道这是怎么了

'use strict';

let path = require('path');
let express = require('express');
let bodyParser = require('body-parser');
let mongoose = require('mongoose');
let formidable = require('express-formidable');
let routes = require('./routes');
let app = express();
let port = process.env.PORT || 3000;


let db = mongoose.connect('mongodb://localhost:27017/old-driver');

// deal with img post
app.use(formidable({
  uploadDir: path.join(__dirname, 'upload'),
  keepExtensions: true
}));

app.use(bodyParser.urlencoded({extended: true })); 
app.use(bodyParser.json());

// access-control
app.all('*', (req, res, next) => {
  res.set("Access-Control-Allow-Origin", "*");
  res.set("Access-Control-Allow-Headers", "Content-Type,X-Requested-With");
  res.set("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  res.set("X-Powered-By",' 3.2.1')
  res.type("application/json");
  res.type("jpg");
  next();
});


// …
Run Code Online (Sandbox Code Playgroud)

node.js express

1
推荐指数
1
解决办法
3364
查看次数

标签 统计

express ×1

node.js ×1