3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.js サブドメインでfavicon出し分け

Posted at
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);
3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?