Skip to content

Commit

Permalink
Added module. prefix to exports to fix some doc issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Abrifq committed Aug 20, 2021
1 parent 388f21c commit 849ce94
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions apiHandlerPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ async function searchAPI(path) {
return APIList.find(api => waitATick().then(() => api.testOn(path)));
}

exports.config = { get shouldServe() { return APIList.pool.size > 0; } };
module.exports.config = { get shouldServe() { return APIList.pool.size > 0; } };

exports.interface = {
module.exports.interface = {
add: addAPI,
remove: removeAPI,
findFirstMatchingAPI: searchAPI
Expand Down
6 changes: 3 additions & 3 deletions blacklistURLPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const filterPool = new Pool();
const { waitATick } = require("./commonUtils");

/**@param {import("./matcher").MatcherTypes} matcher */
exports.add = matcher => filterPool.add(new Matcher(matcher));
module.exports.add = matcher => filterPool.add(new Matcher(matcher));
/**@param {symbol} matcherID */
exports.remove = matcherID => filterPool.remove(matcherID);
module.exports.remove = matcherID => filterPool.remove(matcherID);

/**@param {string} */
exports.isForbidden = path => filterPool.find(filter => waitATick().then(() => filter.testOn(path)))
module.exports.isForbidden = path => filterPool.find(filter => waitATick().then(() => filter.testOn(path)))
.then(function (filter) {
return !!filter;
});
2 changes: 1 addition & 1 deletion commonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
* @returns {Promise<void>}
* This utility function is aimed for taking a breath in async functions, especially the ones with loops.
*/
exports.waitATick = () => new Promise(resolve => setTimeout(resolve, 0));
module.exports.waitATick = () => new Promise(resolve => setTimeout(resolve, 0));
8 changes: 4 additions & 4 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
exports.general = {
module.exports.general = {
hasServerStarted: false,
port: require("process").env["PORT"] || 3000
};

exports.static = require("./staticFileHandler").config;
exports.websocket = require("./websocketHandlerPool").config;
exports.apiPages = require("./apiHandlerPool").config;
module.exports.static = require("./staticFileHandler").config;
module.exports.websocket = require("./websocketHandlerPool").config;
module.exports.apiPages = require("./apiHandlerPool").config;
2 changes: 1 addition & 1 deletion errorPageGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function errorPageGenerator(errorCode, errorMessage) {
* @param {import('http').ServerResponse} response - The Server's ServerResponse class to deliver the http page.
* @param {number} errorNo - The error's status code.
*/
exports.returnErrorPage = function (response, errorNo) {
module.exports.returnErrorPage = function (response, errorNo) {
const errorMessage = httpErrorCodes[errorNo];
response.writeHead(errorNo, errorMessage, { "Content-Type": "text/html; charset=UTF-8" });
response.write(errorPageGenerator(errorNo, errorMessage));
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"directories": {
"test": "tests"
},
"devDependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/fbarda/dirty-serve.git"
Expand Down
14 changes: 7 additions & 7 deletions server-interface.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const config = require("./config");
exports.websocket = config.websocket;
exports.pathFilter = { add, remove } = require("./blacklistURLPool");
exports.apiPageHandlers = { add, remove } = require("./apiHandlerPool").interface;
exports.staticServer = { searchPath, shouldServe } = config.static;
module.exports.websocket = config.websocket;
module.exports.pathFilter = { add, remove } = require("./blacklistURLPool");
module.exports.apiPageHandlers = { add, remove } = require("./apiHandlerPool").interface;
module.exports.staticServer = { searchPath, shouldServe } = config.static;

Object.defineProperty(exports, "port", {
Object.defineProperty(module.exports, "port", {
get: () => config.general.port,
set: (val) => config.general.port = val
});

exports.startServer = require("./server").start;
exports.stopServer = require("./server").stop;
module.exports.startServer = require("./server").start;
module.exports.stopServer = require("./server").stop;
4 changes: 2 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ wsServer.on("request", async function processWebSocketRequest(request) {
eligibleInterface.registerConnection(request.accept());
});

exports.start = () => {
module.exports.start = () => {
return config.hasServerStarted ||
server.listen(config.port, () => { config.hasServerStarted = true; server.ref(); });
};
exports.stop = () => {
module.exports.stop = () => {
if (config.hasServerStarted) {
wsServer.shutDown();
server.close(() => { config.hasServerStarted = false; server.unref(); });
Expand Down
4 changes: 2 additions & 2 deletions staticFileHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ async function respondStatically({ method = "", headers = {} }, response, saniti

}

exports.interface = respondStatically;
exports.config = config;
module.exports.interface = respondStatically;
module.exports.config = config;

/**
* @typedef FileHandler
Expand Down
4 changes: 2 additions & 2 deletions websocketHandlerPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ const removeHandler = symbol => {
websocketHandlersPool.remove(symbol);
};

exports.interface = {
module.exports.interface = {
findFirstEligibleHandler: path => websocketHandlersPool.find(ws => waitATick().then(() => ws.testOn(path))),
add: addHandler,
remove: removeHandler
};

let useNagleAlgorithm = false;
exports.config = {
module.exports.config = {
get shouldServe() { return websocketHandlersPool.pool.size > 0; },
get useNagle() { return useNagleAlgorithm; },
set useNagle(value) { useNagleAlgorithm = !!value; }
Expand Down

0 comments on commit 849ce94

Please sign in to comment.