【问题标题】:tslint: Forbidden http url in stringtslint:字符串中禁止的 http url
【发布时间】:2018-01-30 20:57:57
【问题描述】:
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() 方法上方来忽略此错误,但是还有其他解决方案吗?

【问题讨论】:

    标签: typescript tslint node-fetch


    【解决方案1】:

    这条规则的描述是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 中禁用所有项目的检查

    【讨论】:

      猜你喜欢
      • 2016-06-26
      • 1970-01-01
      • 2019-05-07
      • 2023-03-25
      • 2017-04-17
      • 1970-01-01
      • 1970-01-01
      • 2015-01-18
      • 1970-01-01
      相关资源
      最近更新 更多