Permalink
Browse files

add second param to server.start for specifying web root

  • Loading branch information...
1 parent cb5f7c7 commit 7749becc5e0fc4ad5ce4670508ed6f7549eb13c6 @matthewkastor committed Mar 18, 2013
Showing with 16 additions and 11 deletions.
  1. +8 −4 README.md
  2. +7 −6 atropa-server.js
  3. +1 −1 router.js
View
@@ -1,4 +1,4 @@
-A simple http server for node with lazy module loading.
+A simple http server for node with autoindexing and lazy module loading.
This is a rough draft, really rough. I believe I've got autoindexing
working properly. I've also put in some redirection logic so that the current
@@ -10,9 +10,10 @@ be processed server side. `jsn` files are to be written as modules exporting a
single function which takes the response and request objects and handles them.
The web root is the folder containing your node_modules folder. This server
-automatically finds index.html if given a directory. This server uses the mime
-module to automatically serve files with the proper content type. See the
-documentation on the mime module for instructions on adding custom mime types.
+automatically finds index.html if given a directory. This server uses the [mime
+module](https://npmjs.org/package/mime) to automatically serve files with the
+proper content type. See the documentation on the mime module for instructions
+on adding custom mime types.
# Basic Usage
@@ -38,6 +39,9 @@ In server.js do:
```
var atropaServer = require('atropa-server');
// starting the server on port 9999
+// an optional second parameter for setting the server root
+// as an absolute path may be specified. The server root
+// defaults to `path.dirname(process.mainModule.filename)`
atropaServer.start(9999);
```
View
@@ -9,12 +9,13 @@
vars: true
*/
-var server = require('./server.js'),
- router = require('./router.js'),
- requestHandlers = require('./requestHandlers.js'),
- port = 8888;
-
-function start (userPort) {
+var server = require('./server.js');
+var router = require('./router.js');
+var requestHandlers = require('./requestHandlers.js');
+var path = require('path');
+
+function start (userPort, serverroot) {
+ process.env.serverroot = serverroot || path.dirname(process.mainModule.filename);
userPort = userPort || 8888;
server.start(router.route, requestHandlers, userPort);
}
View
@@ -19,7 +19,7 @@ function route(handle, pathname, response, request) {
var locationIsModule = false;
var locationIsFile = false;
var locationIsDirectory = false;
- var location = path.normalize(__dirname + '/../../' + pathname);
+ var location = path.normalize(process.env.serverroot + '/' + pathname);
if (fs.existsSync(location)) {
if(fs.statSync(location).isFile()) {

0 comments on commit 7749bec

Please sign in to comment.