标头名称必须是有效的HTTP令牌,nodejs?



我正在尝试创建将返回自托管URL的API。这是我的代码

const app = require('./app');
const config = require('./config/config');
const logger = require('./config/logger');
let server;
server = app.listen(config.port, config.host, () => {
logger.info(`Listening to port ${config.port} on host ${config.host}`);
});
app.get('/:sid/:ui',  (req, res, next) => {
console.log('OK')
})
app.get('/url',  (req, res, next) => {
console.log('inside')
res.append(config.host+":"+config.port+"/:sid/:ui")
})

我正在寻找的结果是

http://127.0.0.1:3005/sid/ui

当我点击2 urlhttp://127.0.0.1:3005/url我得到以下错误

TypeError [ERR_INVALID_HTTP_TOKEN]: Header name must be a valid HTTP token ["127.0.0.1:3005/:sid/:ui"]
at ServerResponse.setHeader (node:_http_outgoing:578:3)
at ServerResponse.header (C:Userswguptanode_modulesexpresslibresponse.js:794:10)
at ServerResponse.append (C:Userswguptanode_modulesexpresslibresponse.js:755:15)
at C:Backendtemp1srcindex.js:14:7

res.send()代替res.append()

使用

解决语法问题
res.send(config.host+":"+config.port+"/sid/ui")

相关内容

  • 没有找到相关文章

最新更新