about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2017-10-08 11:18:37 +0200
committerAlan Pearce2017-10-08 11:18:37 +0200
commit6fcfcc550921ab43c00d323c172fd9d04211e53d (patch)
tree2220ab31af63a406f9c4f947e014b022408bf985
parent529946dc5bdccc2153c97e2040953047319480f4 (diff)
downloadhomestead-6fcfcc550921ab43c00d323c172fd9d04211e53d.tar.lz
homestead-6fcfcc550921ab43c00d323c172fd9d04211e53d.tar.zst
homestead-6fcfcc550921ab43c00d323c172fd9d04211e53d.zip
Allow config file to be specified 2017
Currently via environment variable, but for now that's fine as the
only use that I can forsee is for testing, where the plumbing is more
important than the interface.
-rw-r--r--src/app.js16
-rw-r--r--src/index.js5
-rw-r--r--src/modules/config.js11
-rw-r--r--test/app.test.js4
4 files changed, 18 insertions, 18 deletions
diff --git a/src/app.js b/src/app.js
index 20ffb69..e9af4f5 100644
--- a/src/app.js
+++ b/src/app.js
@@ -8,25 +8,23 @@ const helmet = require("koa-helmet");
 const actions = require("./actions.js");
 const responders = require("./responders.js");
 
-const config = require("./modules/config.js");
-
 const Router = require("koa-router");
 const router = new Router();
 
 const makeTagURI = (authority, startDate) => specific =>
   `tag:${authority},${startDate}:${specific}`;
 
-app.context.makeTagURI = makeTagURI(
-  config.feed.originalDomainName,
-  config.feed.domainStartDate
-);
-app.context.getURL = router.url.bind(router);
-
-module.exports = async function() {
+module.exports = async function(config) {
   const Posts = await require("./domain/posts.js")(config.posts, basename =>
     router.url("post", basename)
   );
 
+  app.context.getURL = router.url.bind(router);
+  app.context.makeTagURI = makeTagURI(
+    config.feed.originalDomainName,
+    config.feed.domainStartDate
+  );
+
   router.get("home", "/", actions.home(config, responders.home, Posts.posts));
 
   router.get(
diff --git a/src/index.js b/src/index.js
index b7bc1a3..a9ce7f7 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,7 +1,8 @@
 "use strict";
 
-const config = require("./modules/config.js");
+const getConfig = require("./modules/config.js");
 
+const CONFIG_FILE = process.env.CONFIG_FILE || undefined;
 const PORT = process.env.PORT || config.server.port;
 const targetDir = process.argv[2];
 
@@ -13,7 +14,7 @@ const app = require("./app.js");
 
 (async function() {
   try {
-    (await app()).listen(PORT, () => {
+    (await app(getConfig(CONFIG_FILE))).listen(PORT, () => {
       console.log(`App listening on port ${PORT}`);
     });
   } catch (error) {
diff --git a/src/modules/config.js b/src/modules/config.js
index 72d1b1a..5500323 100644
--- a/src/modules/config.js
+++ b/src/modules/config.js
@@ -4,11 +4,12 @@ const path = require("path");
 const TOML = require("toml");
 const config = require("configly");
 
-module.exports = config(
-  ["./config", path.resolve(__dirname, "../../config/")],
-  {
+function getConfig(configFile = "./config") {
+  return config(["./config", path.resolve(__dirname, "../../config/")], {
     parsers: {
       toml: TOML.parse
     }
-  }
-);
+  });
+}
+
+module.exports = getConfig;
diff --git a/test/app.test.js b/test/app.test.js
index a3f06a1..196041a 100644
--- a/test/app.test.js
+++ b/test/app.test.js
@@ -7,11 +7,11 @@ const cheerio = require("cheerio");
 const mf = require("microformat-node");
 
 process.chdir(path.resolve(__dirname, "./testsite/"));
-const config = require(path.resolve(__dirname, "../src/modules/config.js"));
+const getConfig = require(path.resolve(__dirname, "../src/modules/config.js"));
 
 const App = require("../src/app.js");
 let app;
-test.before(async t => (app = await App()));
+test.before(async t => (app = await App(getConfig("./testsite/config.toml"))));
 
 const parseResponse = res =>
   cheerio.load(res.text, {