Attila Attila - 1 month ago 14
TypeScript Question

tslint: Forbidden http url in string

function getStuff(req: express.Request, res: express.Response, next: express.NextFunction): void {
fetch('http://localhost:3000/stuff')
.then((data: {}) => {
res.send(data.body._readableState.buffer.head.data.toString());
})
.catch((err: {}) => {
res.json(err);
});
}


The error I'm getting is
[tslint] Forbidden http url in string 'http://localhost:3000/stuff' (no-http-string)


I could get this error ignored by putting
// tslint:disable-next-line
above the
fetch()
method, but is there any other solution to this?

Answer Source

Description of this rule is Do not use strings that start with 'http:'. URL strings should start with 'https:'.

1) Put // tslint:disable-next-line:no-http-string above the fetch() method to disable inspection for one line

2) Put

{
    "rules": {
        "no-http-string": false, // <---- this line
    }
}

in tslint.json to disable inspection for all project