host multiple pages on nodejs

前端 未结 2 1497
独厮守ぢ
独厮守ぢ 2021-02-06 03:47

So I have my app at http://localhost:8080/

How can I have http://localhost:8080/subpage ? Because it seems like any page that hits :8080 pulls

2条回答
  •  面向向阳花
    2021-02-06 04:40

    Here is a start:

    var http=require('http');
    var url=require('url');
    
    var server=http.createServer(function(req,res){
        var pathname=url.parse(req.url).pathname;
        switch(pathname){
            case '/subpage':
                res.end('subpage');
            break;
            default:
                res.end('default');
            break;
        }
    
    }).listen(8080);
    

提交回复
热议问题