I am trying to create API which will return self hosted URL. This is my code
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")
})
I am looking for result to be as
http://127.0.0.1:3005/sid/ui
When I hit the 2 url http://127.0.0.1:3005/url
I get the following error
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:\Users\wgupta\node_modules\express\lib\response.js:794:10)
at ServerResponse.append (C:\Users\wgupta\node_modules\express\lib\response.js:755:15)
at C:\Backend\temp1\src\index.js:14:7
CodePudding user response:
Use res.send()
instead of res.append()
CodePudding user response:
Syntax issue solved it using
res.send(config.host ":" config.port "/sid/ui")