Hemanth.HM

A Computer Polyglot, CLI + WEB ♥'r.

HTTP Status Code as a Service

| Comments

There are few HTTP status serivce apps, /me pawed a bit with node to do the same. Do try HSCO.

The code is plain and simple :

1
2
3
4
5
6
7
8
var http = require('http');
var url = require("url");
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  var url_parts = url.parse(req.url, true);
  var status = url_parts.pathname.replace(/^\/([^\/]*).*$/, '$1');
  res.end(http.STATUS_CODES[status] || "Undefined status : "+ status || "Try /404");
}).listen(process.env.PORT || 5000);

Well, this can be improved futher...this is just the first cut.

Comments