-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
81 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Get optional args | ||
var args = process.argv.splice(2); | ||
var formattedArgs = {}; | ||
|
||
// Simple args parse | ||
for (var i = 0, l = args.length; i < l; i ++) { | ||
if (args[i].match(/^-+/)) { | ||
formattedArgs[args[i]] = args[i + 1]; | ||
} | ||
}; | ||
|
||
// Setup constants | ||
var ROOT_PATH = ''; | ||
var PORT = formattedArgs['--port'] || 3000; | ||
|
||
if (formattedArgs['--root']) { | ||
ROOT_PATH += formattedArgs['--root'] + '/'; | ||
} | ||
|
||
var server = require('../server'); | ||
server.start(PORT, ROOT_PATH); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var types = require('./types'); | ||
|
||
module.exports = { | ||
getType: function (url) { | ||
var type = url.split('.').pop(); | ||
// Default extension | ||
if (type === '/') { | ||
type = 'html'; | ||
} | ||
return types[type]; | ||
}, | ||
|
||
notFound : function(url, res) { | ||
console.log('Could find ', url); | ||
res.writeHead(404, {"Content-Type": 'text/html'}); | ||
res.end(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
'js' : 'application/javascript', | ||
'json': 'application/json', | ||
'html' : 'text/html', | ||
'png': 'image/png', | ||
'jpeg': 'image/jpeg', | ||
'gif': 'image/gif' | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
"version": "0.0.1", | ||
"description": "Simple http server", | ||
"main": "server.js", | ||
"bin": { | ||
"server" : "bin/cli.js" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "node server.js" | ||
|
@@ -15,10 +18,20 @@ | |
"HTTP", | ||
"server" | ||
], | ||
"author": "Daniel Paulino", | ||
"author": { | ||
"name": "Daniel Paulino" | ||
}, | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/dpsxp/node-http-server/issues" | ||
}, | ||
"homepage": "https://github.com/dpsxp/node-http-server" | ||
"homepage": "https://github.com/dpsxp/node-http-server", | ||
"readme": "node-http-server\n================\n\nNodeJS Simple HTTP Server\n\nThis a simple HTTP server made with nodejs. \nI know there's a lot of http server around, and also I should be using some task runner (because that's what cool kids are doing), But I made this one to better understand how nodejs work.\n\n## How to use\n\nFor now just copy it and run \n\n node server.js\n\nYou can also set optional params \n\n node server.js --root ROOT_PATH --port PORT\n\n", | ||
"readmeFilename": "README.md", | ||
"_id": "[email protected]", | ||
"dist": { | ||
"shasum": "d53b6de5a53ec61398e1875c12691670bab4edbf" | ||
}, | ||
"_resolved": "git+https://github.com/dpsxp/node-http-server.git#4e6fcd42cea59ee293de2ea2337135aab35e11a5", | ||
"_from": "git+https://github.com/dpsxp/node-http-server.git" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters