Javascript 如何在平均堆栈中设置HTTP头密钥/值对
我使用的是平均堆栈,需要在我的web应用程序中设置HTTP头密钥/值对 i、 e.Javascript 如何在平均堆栈中设置HTTP头密钥/值对,javascript,angular,express,http-headers,mean-stack,Javascript,Angular,Express,Http Headers,Mean Stack,我使用的是平均堆栈,需要在我的web应用程序中设置HTTP头密钥/值对 i、 e.my\u键:my\u值 使用Angular 5并找到以下代码: app.use('/api', function (req, res) { let url = config.API_HOST + req.ur req.headers['someHeader'] = 'someValue' req.pipe(request(url)).pipe(res) }) 但不确定如何应用于我的要求,因为
my\u键:my\u值
使用Angular 5并找到以下代码:
app.use('/api', function (req, res) {
let url = config.API_HOST + req.ur
req.headers['someHeader'] = 'someValue'
req.pipe(request(url)).pipe(res)
})
但不确定如何应用于我的要求,因为我认为我需要上述代码中的唯一一行是:
req.headers['my_key'] = 'my_value'
但不确定我是否需要
req.pipe
行。在npm上至少使用一个中间件来处理Express中的COR:[请参阅@mscdex-answer]
将标题字段设置为值
res.set('Content-Type', 'text/plain');
或传递一个对象以同时设置多个字段
res.set({
'Content-Type': 'text/plain',
'Content-Length': '456'
})
化名为
res.header(field, [value])
有关更多信息,请阅读在npm上使用至少一个中间件来处理Express中的COR:[请参阅@mscdex-answer] 将标题字段设置为值
res.set('Content-Type', 'text/plain');
或传递一个对象以同时设置多个字段
res.set({
'Content-Type': 'text/plain',
'Content-Length': '456'
})
化名为
res.header(field, [value])
有关更多信息,请阅读