Skip to content

Commit a827da2

Browse files
committed
Remove nodemon and fb-flo from cli and add wordy option
1 parent ee5af13 commit a827da2

File tree

6 files changed

+54
-101
lines changed

6 files changed

+54
-101
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ Basic usage:
2121
```javascript
2222
var server = require('fast-http'),
2323
port = 80,
24-
root = __dirname;
24+
root = __dirname,
25+
wordy = true;
2526

26-
server(port, root);
27+
server(port, root, wordy);
2728

2829
// __dirname is the name of the directory that the currently executing script resides in.
2930
```
3031

32+
The third argument specified if it\'ll log all request.
33+
3134
If you want to use it with socket.io:
3235

3336
```javascript
34-
var server = require('fast-http')(80, __dirname);
37+
var server = require('fast-http')(80, __dirname, false);
3538

3639
var io = require('socket.io').listen(server);
3740
```
@@ -46,13 +49,15 @@ npm install fast-http-cli -g
4649
```
4750

4851
Options:
52+
```
53+
-h, --help output usage information
4954
50-
-h, --help output usage information
55+
-V, --version output the version number
5156
52-
-V, --version output the version number
57+
-p, --port [number] specified the port
5358
54-
-p, --port [number] specified the port
55-
59+
-w, --wordy specified if it'll log all request
60+
```
5661

5762
Use:
5863
```bash

cli/README.md

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Fast Http CLI
22

3+
Use [fast-http](https://www.npmjs.org/package/fast-http) with a command!
4+
35
[![Build Status](https://travis-ci.org/cedced19/fast-http.svg)](https://travis-ci.org/cedced19/fast-http)
46
[![NPM version](https://badge.fury.io/js/fast-http-cli.svg)](http://badge.fury.io/js/fast-http-cli)
57

6-
Use [fast-http](https://www.npmjs.org/package/fast-http) with a command!
7-
88
## Installation
99

1010
```bash
@@ -26,26 +26,5 @@ fast-http
2626
2727
-p, --port [number] specified the port
2828
29-
-o, --open open in the browser
30-
31-
-n, --nodemon use nodemon with your node project
29+
-w, --wordy specified if it'll log all request
3230
```
33-
34-
## Fb-flo Integration
35-
36-
### 1. Install the Chrome Extension
37-
38-
Grab the [fb-flo Chrome extension](https://chrome.google.com/webstore/detail/ahkfhobdidabddlalamkkiafpipdfchp). This will add a new tab in your Chrome DevTools called 'flo'.
39-
40-
### 2. Activate fb-flo
41-
42-
To activate fb-flo from the browser:
43-
44-
* Open Chrome DevTools.
45-
46-
* Click on the new 'fb-flo' pane.
47-
48-
* Click on 'Activate for this site'
49-
50-
See screenshot:
51-
![](http://i.imgur.com/SamY32i.png)

cli/fast-http.js

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,37 @@
11
#!/usr/bin/env node
22
'use strict';
33

4-
var colors = require('colors'),
5-
server = require('fast-http'),
4+
var server = require('fast-http'),
65
opn = require('opn'),
7-
path = require('path'),
8-
fs = require('fs'),
96
program = require('commander'),
10-
nodemon = require('nodemon'),
117
port = 80,
128
test = require('net').createServer();
139

1410
program
1511
.version(require('./package.json').version)
1612
.option('-p, --port [number]', 'specified the port')
1713
.option('-o, --open', 'open in the browser')
18-
.option('-n, --nodemon', 'use nodemon with your node project')
14+
.option('-w, --wordy', 'specified if it\'ll log all request')
1915
.parse(process.argv);
2016

2117
if (!isNaN(parseFloat(program.port)) && isFinite(program.port)){
2218
port = program.port;
2319
}
2420

2521
test.once('error', function(err) {
26-
console.log('\n\'' + 'fast-http'.cyan + '\':' + 'This port is already used!\n'.red);
22+
console.log('This port is already used!');
2723
process.exit(1);
2824
});
2925

3026
test.once('listening', function() {
3127
test.close();
32-
if (program.nodemon) {
33-
nodemon({
34-
script: require(process.cwd() + '/package.json').main,
35-
ext: 'js json',
36-
ignore: 'vendor'
37-
});
38-
nodemon.on('start', function () {
39-
console.log('\'' + 'nodemon'.cyan + '\': App has started.\n');
40-
}).on('quit', function () {
41-
console.log('\n\'' + 'nodemon'.cyan + '\': App has quit.\n');
42-
}).on('restart', function (files) {
43-
console.log('\n\'' + 'nodemon'.cyan + '\': App restarted due to: ' + files);
44-
});
45-
} else {
46-
server(port, process.cwd());
47-
}
28+
29+
server(port, process.cwd(), program.wordy);
30+
4831

4932
if (program.open){
5033
opn('http://localhost:' + port);
5134
}
52-
53-
require('fb-flo')(
54-
process.cwd(),
55-
{
56-
port: 8888,
57-
host: 'localhost',
58-
verbose: false,
59-
glob: [
60-
'**/*.js',
61-
'**/*.css',
62-
'**/*.html'
63-
]
64-
},
65-
function resolver(filepath, callback) {
66-
callback({
67-
resourceURL: path.extname(filepath),
68-
contents: fs.readFileSync(filepath),
69-
reload: true,
70-
update: function(_window, _resourceURL) {
71-
console.log('Resource ' + _resourceURL + ' has just been updated with new content');
72-
}
73-
});
74-
}
75-
);
7635
});
7736

7837
test.listen(port);

cli/package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fast-http-cli",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "Use fast-http with a command!",
55
"main": "fast-http.js",
66
"engines": {
@@ -23,18 +23,20 @@
2323
"author": {
2424
"name": "cedced19"
2525
},
26-
"license": "MIT",
26+
"licenses": [
27+
{
28+
"type": "MIT",
29+
"url": "http://cedced19.github.io/license/"
30+
}
31+
],
2732
"bugs": {
2833
"url": "https://github.com/cedced19/fast-http/issues"
2934
},
3035
"homepage": "https://github.com/cedced19/fast-http",
3136
"dependencies": {
32-
"colors": "1.0.3",
3337
"commander": "^2.5.0",
34-
"fast-http": "0.1.2",
35-
"fb-flo": "^0.3.1",
36-
"nodemon": "^1.3.7",
37-
"opn": "^1.0.0"
38+
"fast-http": "0.1.3",
39+
"opn": "^3.0.2"
3840
},
3941
"engineStrict": true,
4042
"preferGlobal": true

index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
1+
'use strict';
12
var http = require('http'),
23
url = require('url'),
34
path = require('path'),
45
mime = require('mime'),
56
fs = require('fs');
67

7-
module.exports = function (port, root) {
8-
var server = http.createServer(function(req, res) {
8+
module.exports = function (port, root, wordy) {
9+
if (wordy === undefined) wordy = false;
10+
if (port === undefined) port = 80;
11+
var server = http.createServer(function (req, res) {
912

1013
var uri = url.parse(req.url).pathname,
1114
filename = path.join(root, uri);
1215

13-
if (uri.charAt(uri.length-1) == '/'){
14-
filename += 'index.html'
16+
if (uri.charAt(uri.length - 1) === '/') {
17+
filename += 'index.html';
1518
}
1619

17-
console.log('GET:' + uri + ' -> ' + filename);
20+
if (wordy) console.log('GET:' + uri + ' -> ' + filename);
1821

19-
fs.exists(filename, function(exists) {
20-
if(!exists) {
21-
console.log('Error 404');
22+
fs.exists(filename, function (exists) {
23+
if (!exists) {
24+
if (wordy) console.log('Error 404');
2225
res.writeHead(404, {'Content-Type': 'text/plain'});
2326
res.end('Error 404');
2427
return;
2528
}
26-
if (fs.statSync(filename).isDirectory() && uri.charAt(uri.length-1) != '/') {
27-
console.log('Redirection 303');
29+
if (fs.statSync(filename).isDirectory() && uri.charAt(uri.length - 1) !== '/') {
30+
if (wordy) console.log('Redirection 303');
2831
res.writeHead(303,{ 'Location': uri + '/' });
2932
res.end('Redirecting to: ' + uri + '/');
3033
return;
3134
}
32-
fs.readFile(filename,'binary', function(err, file) {
35+
fs.readFile(filename, 'binary', function(err, file) {
3336
if(err) {
34-
console.log('Error 500');
37+
if (wordy) console.log('Error 500');
3538
res.writeHead(500, {'Content-Type': 'text/plain'});
3639
res.end('Error 500');
3740
return;
3841
}
39-
console.log('Ok 200');
42+
if (wordy) console.log('Ok 200');
4043
res.writeHead(200, {
4144
'Content-Type': mime.lookup(filename) + ';' + mime.charsets.lookup(mime.lookup(filename))
4245
});

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fast-http",
3-
"version": "0.1.2",
4-
"description": "Create a tiny web server which does not support the MVC pattern,for simple Node.js app.",
3+
"version": "0.1.3",
4+
"description": "Create a tiny web server which does not support the MVC pattern, for simple Node.js app.",
55
"main": "index.js",
66
"engines": {
77
"node": ">=0.10.0"
@@ -19,7 +19,12 @@
1919
"author": {
2020
"name": "cedced19"
2121
},
22-
"license": "MIT",
22+
"licenses": [
23+
{
24+
"type": "MIT",
25+
"url": "http://cedced19.github.io/license/"
26+
}
27+
],
2328
"bugs": {
2429
"url": "https://github.com/cedced19/fast-http/issues"
2530
},

0 commit comments

Comments
 (0)