全栈:静态网址

静态网址

 实例:

//静态网址
var http = require('http')
var querystring = require('querystring');
var fs = require('fs')
var url = require('url')

var app = http.createServer((req, res) => {
    let urlobj = url.parse(req.url)
    let pathname = urlobj.pathname
    let path = __dirname + '/src' + pathname
    fs.readFile(path)
    if (pathname == '/') {
        path = 'src/index.html'
    }
    fs.readFile(path, (err, data) => {
        if (!err) {
            res.end(data)
        } else {
            res.end('404')
        }
    })
})
app.listen(8080)

 

posted on 2022-08-01 20:57  香香鲲  阅读(32)  评论(0编辑  收藏  举报