Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.请求 http://localhost:8080/index.html路径的时候,显示index.html的内容。 #3

Open
zhufengnodejs opened this issue Apr 12, 2016 · 4 comments

Comments

@zhufengnodejs
Copy link
Owner

姓名

http.createServer(function(request,response)
@lizhongwu
Copy link

李仲午

var http = require("http");
var server = http.createServer(function (request, response) {
    if(request.url === "/index.html"){
        var fs = require("fs");
        fs.readFile("index.html", "utf8", function (err, data) {
            response.write(data);
            response.end();
        });
    } else {
        response.end();
    }
});
server.listen(8080);

@lucian55
Copy link

刘绍振
var http=require("http");
var server=http.createServer(function(request,response){
var url=request.url;
console.log(url);
if(url=="/index.html"){
var fs=require("fs");
fs.readFile("index.html","utf8",function(error,data){
console.log(data);
response.write(data);
})
}
//response.end();
});
server.listen(8080);

@zhangxu0917
Copy link

张旭

var http = require("http");
var fs = require("fs");
var content = fs.readFileSync("index.html","utf8");
var server = http.createServer(function(req,res){
    res.setHeader("Content-type","text/html;charset=utf-8");
    var  url = req.url;
    if(url == "/index.html") {
        res.write(content);
        res.end();
    }else{
        res.write("");
        res.end();
    }
})
server.listen(8000,"localhost");

@zl399615007
Copy link

郑龙

var http=require('http');
var fs=require('fs');
var server=http.createServer(function (request,response){
    if(request.url=='/index.html'){
       fs.readFile('index.html','utf8',function (err,data){
            response.write(data);
           response.end();
        })
    }else {
        response.write('not found');
        response.end();
    }
});
server.listen(8070);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants