summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2017-06-18 20:07:14 +0200
committerAlan Pearce2017-06-18 20:07:14 +0200
commit2fef943bf1c52e8d2be64521202936ca0f7358e3 (patch)
treeef839e7442e7a996dc3f8c918529a500b7efa53e
parente13c5726846a89df4196f6abc9fc98d99d48305b (diff)
downloadhomestead-2fef943bf1c52e8d2be64521202936ca0f7358e3.tar.lz
homestead-2fef943bf1c52e8d2be64521202936ca0f7358e3.tar.zst
homestead-2fef943bf1c52e8d2be64521202936ca0f7358e3.zip
feat: use configly/TOML for configuration
-rw-r--r--config/default.toml5
-rw-r--r--package.json4
-rw-r--r--src/index.js8
-rw-r--r--src/modules/config.js10
-rw-r--r--test/index.test.js4
-rw-r--r--yarn.lock37
6 files changed, 62 insertions, 6 deletions
diff --git a/config/default.toml b/config/default.toml
new file mode 100644
index 0000000..3026849
--- /dev/null
+++ b/config/default.toml
@@ -0,0 +1,5 @@
+[server]
+port = 3000
+
+[posts]
+folder = "../posts"
\ No newline at end of file
diff --git a/package.json b/package.json
index e25d390..93f2ddf 100644
--- a/package.json
+++ b/package.json
@@ -29,10 +29,12 @@
     "supertest": "^3.0.0"
   },
   "dependencies": {
+    "configly": "^4.1.0",
     "gray-matter": "^2.1.1",
     "koa": "^2.2.0",
     "koa-nunjucks-next": "^1.1.3",
     "koa-router": "^7.2.1",
-    "markdown-it": "^8.3.1"
+    "markdown-it": "^8.3.1",
+    "toml": "^2.3.2"
   }
 }
diff --git a/src/index.js b/src/index.js
index 242b298..6df1530 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,17 +1,19 @@
 'use strict'
 
-const PORT = process.env.PORT || 3000
-
 const Koa = require('koa')
 const app = new Koa()
 
+const config = require('./modules/config.js')
+
+const PORT = process.env.PORT || config.server.port
+
 const Router = require('koa-router')
 const router = new Router()
 
 const view = require('koa-nunjucks-next')
 
 const Posts = require('./modules/posts.js')
-const posts = Posts.getFolder(process.env.POST_DIR)
+const posts = Posts.getFolder(config.posts.folder)
 
 app.use(
   view(`${__dirname}/views`, {
diff --git a/src/modules/config.js b/src/modules/config.js
new file mode 100644
index 0000000..461945d
--- /dev/null
+++ b/src/modules/config.js
@@ -0,0 +1,10 @@
+'use strict'
+
+const TOML = require('toml')
+const config = require('configly')
+
+module.exports = config({
+  parsers: {
+    toml: TOML.parse
+  }
+})
diff --git a/test/index.test.js b/test/index.test.js
index e13e52c..926c5d4 100644
--- a/test/index.test.js
+++ b/test/index.test.js
@@ -2,7 +2,9 @@ const test = require('ava')
 const path = require('path')
 const request = require('supertest')
 
-process.env.POST_DIR = path.resolve(__dirname, '../test/data/')
+const config = require('../src/modules/config.js')
+config.posts.folder = path.resolve(__dirname, './data/')
+
 const app = require('../src/index.js')
 
 test('homepage', t => {
diff --git a/yarn.lock b/yarn.lock
index 297ce30..f4406a4 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -941,6 +941,10 @@ commondir@^1.0.1:
   version "1.0.1"
   resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
 
+compare-property@^2.0.0:
+  version "2.0.0"
+  resolved "https://registry.yarnpkg.com/compare-property/-/compare-property-2.0.0.tgz#e535ae960832a16ab01c5e6af2e96bc845134700"
+
 component-emitter@^1.2.0:
   version "1.2.1"
   resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6"
@@ -957,6 +961,16 @@ concat-stream@^1.5.2:
     readable-stream "^2.2.2"
     typedarray "^0.0.6"
 
+configly@^4.1.0:
+  version "4.1.0"
+  resolved "https://registry.yarnpkg.com/configly/-/configly-4.1.0.tgz#48a6af73cddd1e4d98d44fe264b78db2b0880bce"
+  dependencies:
+    compare-property "^2.0.0"
+    deeply "^2.0.3"
+    fulcon "^1.0.2"
+    precise-typeof "^1.0.2"
+    stripbom "^3.0.0"
+
 configstore@^3.0.0:
   version "3.1.0"
   resolved "https://registry.yarnpkg.com/configstore/-/configstore-3.1.0.tgz#45df907073e26dfa1cf4b2d52f5b60545eaa11d1"
@@ -1127,6 +1141,13 @@ deep-is@~0.1.3:
   version "0.1.3"
   resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
 
+deeply@^2.0.3:
+  version "2.0.3"
+  resolved "https://registry.yarnpkg.com/deeply/-/deeply-2.0.3.tgz#613b1fe7380c00e36df896872f0efaecb1642342"
+  dependencies:
+    fulcon "^1.0.1"
+    precise-typeof "^1.0.2"
+
 define-properties@^1.1.2:
   version "1.1.2"
   resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.2.tgz#83a73f2fea569898fb737193c8f873caf6d45c94"
@@ -1756,6 +1777,10 @@ fstream@^1.0.0, fstream@^1.0.10, fstream@^1.0.2:
     mkdirp ">=0.5 0"
     rimraf "2"
 
+fulcon@^1.0.1, fulcon@^1.0.2:
+  version "1.0.2"
+  resolved "https://registry.yarnpkg.com/fulcon/-/fulcon-1.0.2.tgz#8a4dfda4c73fcd9cc62a79d5045c392b45547320"
+
 function-bind@^1.0.2, function-bind@^1.1.0:
   version "1.1.0"
   resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.0.tgz#16176714c801798e4e8f2cf7f7529467bb4a5771"
@@ -2156,7 +2181,7 @@ is-binary-path@^1.0.0:
   dependencies:
     binary-extensions "^1.0.0"
 
-is-buffer@^1.1.5:
+is-buffer@^1.1.1, is-buffer@^1.1.5:
   version "1.1.5"
   resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc"
 
@@ -3393,6 +3418,12 @@ pluralize@^1.2.1:
   version "1.2.1"
   resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-1.2.1.tgz#d1a21483fd22bb41e58a12fa3421823140897c45"
 
+precise-typeof@^1.0.2:
+  version "1.0.2"
+  resolved "https://registry.yarnpkg.com/precise-typeof/-/precise-typeof-1.0.2.tgz#db8ed470fd08470f5ef7c9b08ee70d6dd5232f0b"
+  dependencies:
+    is-buffer "^1.1.1"
+
 prelude-ls@~1.1.2:
   version "1.1.2"
   resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
@@ -4049,6 +4080,10 @@ strip-json-comments@~2.0.1:
   version "2.0.1"
   resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
 
+stripbom@^3.0.0:
+  version "3.0.0"
+  resolved "https://registry.yarnpkg.com/stripbom/-/stripbom-3.0.0.tgz#0159d615b4ebcdfa78aae57c87d4f81e96ed979b"
+
 superagent@^3.0.0:
   version "3.5.2"
   resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.5.2.tgz#3361a3971567504c351063abeaae0faa23dbf3f8"