var fs = require('fs');
var http = require('http');
var html = '<html><body>test</body></html>'
http.createServer(function (request, response) {
var host = request.headers.host
var arrayOfStrings = host.split('.hostname.');
var path = 'static';
if (arrayOfStrings.length == 2){
path = path + '/' + arrayOfStrings[0];
}
if(request.url == '/favicon.ico'){ //ファビコン
var buf = fs.readFileSync( path + '/favicon.ico');
response.writeHead(200, {"Content-Type": "image/vnd.microsoft.icon"});
response.end(buf);
} else { //ファビコン以外
response.writeHead(200, {'Content-Type': 'text/html'});
response.end(html);
}
}).listen(8888);
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme