Skip to content

Commit

Permalink
convert path to options, #175
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jul 12, 2021
1 parent 83d9b18 commit 78a50d0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions js/common/withServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) => {


Expand All @@ -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 = {
Expand Down

0 comments on commit 78a50d0

Please sign in to comment.