节点TypeError:checkURL不是函数

时间:2019-09-28 16:54:59

标签: javascript node.js

为什么会产生TypeError checkURL不是函数。我也搜索了一些较旧的问题,但不知道为什么会显示错误。

const Server = {
    checkURL: function(url, matchWith) {
        return url === matchWith;
    },

    respond: function(res, status, cType, data ) {
        res.writeHead(status, {
            'Content-Type': cType,
        })
        res.write(data)
        res.end() 
    },

    streams: function(req, res) {
        if (this.checkURL(req, '/')) {
            this.respond(res, 200, 'text/html', `<h2>HELLO</h2>`)
        }
    },
    init: function(PORT) {
        require('http')
            .createServer(this.streams)
            .listen(PORT, () => {
                console.log(`Listening on <${PORT}>`)
            })
        return this
    }
}

module.exports = Server

0 个答案:

没有答案