-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 changed file
with
9 additions
and
3 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 |
---|---|---|
|
@@ -4,22 +4,28 @@ | |
* A simple webserver that will serve the git root on a specific port for the duration of an async callback | ||
* | ||
* @author Jonathan Olson <[email protected]> | ||
* @author Michael Kauzmann (PhET Interactive Simulations) | ||
*/ | ||
|
||
|
||
const http = require( 'http' ); | ||
const fs = require( 'fs' ); | ||
const _ = require( 'lodash' ); // eslint-disable-line require-statement-match | ||
const winston = require( 'winston' ); | ||
|
||
/** | ||
* A simple webserver that will serve the git root on a specific port for the duration of an async callback | ||
* @public | ||
* | ||
* @param {async function(port:number)} asyncCallback | ||
* @param {string} [path] | ||
* @param {Object} [options] | ||
* @returns {Promise} | ||
*/ | ||
module.exports = function( asyncCallback, path = '..' ) { | ||
module.exports = function( asyncCallback, options ) { | ||
options = _.merge( { | ||
path: '../' | ||
}, options ); | ||
|
||
return new Promise( ( resolve, reject ) => { | ||
|
||
|
||
|
@@ -28,7 +34,7 @@ module.exports = function( asyncCallback, path = '..' ) { | |
|
||
// Trim query string | ||
const tail = req.url.indexOf( '?' ) >= 0 ? req.url.substring( 0, req.url.indexOf( '?' ) ) : req.url; | ||
const fullPath = `${process.cwd()}/${path}${tail}`; | ||
const fullPath = `${process.cwd()}/${options.path}${tail}`; | ||
|
||
// See https://gist.github.com/aolde/8104861 | ||
const mimeTypes = { | ||
|