Serving static files with restify

前端 未结 7 1596
时光说笑
时光说笑 2020-12-29 20:26

I am learning to use Node.js. Currently, I have a folder structure that looks like the following:

index.html
server.js
client
  index.html
  subs
    index.h         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 20:48

    server.get('/', function(req, res, next) {
        fs.readFile(__dirname + '/index.html', function (err, data) {
            if (err) {
                next(err);
                return;
            }
            res.setHeader('Content-Type', 'text/html');
            res.writeHead(200);
            res.end(data);
            next();
        });
    });
    

提交回复
热议问题