tslint:字符串中禁止的http url

时间:2017-08-22 14:06:13

标签: typescript tslint node-fetch

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);
        });
}

我得到的错误是[tslint] Forbidden http url in string 'http://localhost:3000/stuff' (no-http-string)

我可以通过将// tslint:disable-next-line放在fetch()方法之上来忽略此错误,但是还有其他解决办法吗?

1 个答案:

答案 0 :(得分:2)

此规则的说明为Do not use strings that start with 'http:'. URL strings should start with 'https:'.

1)将// tslint:disable-next-line:no-http-string置于fetch()方法之上,以禁用对一行的检查

2)放

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

禁用所有项目的检查