Skip to content

Commit

Permalink
Fixes bug from wrong detection of modules
Browse files Browse the repository at this point in the history
  • Loading branch information
aleph-naught2tog committed Jan 22, 2019
1 parent 4c50c06 commit c3a0b66
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion server/index.doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ const url = require('url'); // docs: https://nodejs.org/api/url.html
*/
const PORT = 3000;

/**
* This is how we determine whether or not a module is being requested. This doesn't need to be a full path -- just something unique to identify a request by. If the folder your compiled script end up in is `src`, then the referer will contain `/src/`. (Those slashes are slashes as in a folder path, _not_ as in a regular expression delimiter.)
*
* @constant {string} SRC_BUILD_FOLDER_PATTERN
*/
const SRC_BUILD_FOLDER_PATTERN = '/src/';

/**
* This is the 'root' of the server; it is what all other paths are relative to.
*
Expand Down Expand Up @@ -75,12 +82,13 @@ const determineContentType = extension => {
*/
const isModuleRequest = request => {
// `referer` is the header that represents who made the request
/** @type {string} */
const referer = request.headers.referer;

if (!referer) {
return false;
} else {
return referer.endsWith('.js');
return referer.includes(SRC_BUILD_FOLDER_PATTERN);
}

};
Expand Down
3 changes: 2 additions & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path');
const url = require('url');

const PORT = 3000;
const SRC_BUILD_FOLDER_PATTERN = '/src/';
const SERVER_ROOT_FOLDER = './public';

const determineContentType = extension => {
Expand All @@ -27,7 +28,7 @@ const isModuleRequest = request => {
if (!referer) {
return false;
} else {
return referer.endsWith('.js');
return referer.includes(SRC_BUILD_FOLDER_PATTERN);
}
};

Expand Down

0 comments on commit c3a0b66

Please sign in to comment.