Skip to content

Commit

Permalink
0.0.9
Browse files Browse the repository at this point in the history
Now if you have a 404.html and 500.html at root of the project this page will be display, else a default text will be display.
  • Loading branch information
cedced19 committed Aug 21, 2014
1 parent 05890db commit 6758187
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,25 @@ Because I copy the same code in all my projects.
## How to use

~~~ javascript
var fastHttp = require("fast-http"),
var fastHttp = require('fast-http'),
port = 80;

httpServer = fastHttp(port);
~~~
~~~

## Error

If you have a 404.html and 500.html at root of the project this page will be display,
else a default text will be display.

## CLI

Installation:
```
npm install fast-http-cli -g
```

Use:
```
fast-http <port>
```
18 changes: 15 additions & 3 deletions fast-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ function fastHttp (port) {
path.exists(filename, function(exists) {
if(!exists) {
response.writeHead(404, {'Content-Type': 'text/html'});
fs.createReadStream('404.html').pipe(response);
path.exists('404.html', function(exists) {
if(!exists) {
response.end('Error 404');
return;
}
fs.createReadStream('404.html').pipe(response);
});
return;
}

Expand All @@ -34,11 +40,17 @@ function fastHttp (port) {
fs.readFile(filename, 'binary', function(err, file) {
if(err) {
response.writeHead(500, {'Content-Type': 'text/html'});
fs.createReadStream('500.html').pipe(response);
path.exists('500.html', function(exists) {
if(!exists) {
response.end('Error 500');
return;
}
fs.createReadStream('500.html').pipe(response);
});
return;
}

var headers = {};
var headers = new Object();
var contentType = contentTypesByExtension[path.extname(filename)];
if (contentType) headers['Content-Type'] = contentType;
response.writeHead(200, headers);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fast-http",
"version": "0.0.7",
"version": "0.0.9",
"description": "Create a tiny web server which does not support the MVC pattern,for simple Node.js app.",
"main": "fast-http.js",
"engines": {
Expand Down

0 comments on commit 6758187

Please sign in to comment.