【发布时间】:2021-05-23 05:28:22
【问题描述】:
我正在尝试将来自 IOS 的通用链接的标头内容类型设置为 application/json,但仍然响应
Content-Type: application/octet-stream
但应该是
'Content-Type', 'application/json'
我的简单 server.js 如下所示:
// Install express server
const express = require('express');
const path = require('path');
const app = express();
// Serve only the static files form the dist directory
app.use(express.static(__dirname + '/dist'));
app.use(function (req, res, next) {
res.setHeader('Content-Type', 'application/json');
res.header('Content-Type', 'application/json');
next();
});
app.get(
'/dist/.well-known/apple-app-site-association',
function (req, res, next) {
console.log('it is not console.logged');
res.header('Content-Type', 'application/json');
res.sendFile(
path.join(__dirname + '/dist/.well-known/apple-app-site-association')
);
res.setHeader('Content-Type', 'application/json');
req.header('Content-Type', 'application/json');
}
);
app.get('/*', function (req, res) {
console.log('can log here');
res.setHeader('Content-Type', 'application/json');
res.sendFile(path.join(__dirname + '/dist/index.html'));
res.header('Content-Type', 'application/json');
});
// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 8080);
如何设置header内容类型为application/json?
【问题讨论】:
标签: javascript ios node.js express