Skip to content

Commit

Permalink
Merge pull request #186 from dadi/feature/3.0.0
Browse files Browse the repository at this point in the history
Version 3.0.0 🤙
  • Loading branch information
jimlambie authored Jul 4, 2017
2 parents 7f61043 + 59ad82c commit 1255df3
Show file tree
Hide file tree
Showing 41 changed files with 2,044 additions and 1,388 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ notifications:
email: false
node_js:
- '6'
- '5'
- '4'
before_script:
- npm prune
branches:
Expand Down
54 changes: 6 additions & 48 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,50 +230,6 @@ var conf = convict({
}
}
},
dust: {
cache: {
doc: 'If true, compiled templates are saved to the Dust cache. Recommended setting: true',
format: Boolean,
default: true
},
debug: {
doc: '',
format: Boolean,
default: false
},
debugLevel: {
doc: 'One of [ DEBUG | INFO | WARN | ERROR ]',
format: String,
default: 'WARN'
},
whitespace: {
doc: 'Minify the HTML output',
format: Boolean,
default: false
},
clientRender: {
enabled: {
doc: 'If true, compiled templates are made available to the client-side',
format: Boolean,
default: false
},
format: {
doc: "Defines whether compiled templates are written to individual JS files ('separate') or combined into a single one ('combined')",
format: ['separate', 'combined'],
default: 'separate'
},
path: {
doc: "The location where compiled templates should be written to, relative to 'public'. This should be a folder when 'format' is 'separate' and a file when 'combined'",
format: String,
default: 'templates'
},
whitelist: {
doc: 'When defined, only templates with names matching an entry in whitelist will be made available to the client. Wildcards supported.',
format: Array,
default: []
}
}
},
headers: {
useGzipCompression: {
doc: "If true, uses gzip compression and adds a 'Content-Encoding:gzip' header to the response.",
Expand Down Expand Up @@ -352,12 +308,9 @@ var conf = convict({
default: {
datasources: path.join(__dirname, '/workspace/datasources'),
events: path.join(__dirname, '/workspace/events'),
filters: path.join(__dirname, '/workspace/utils/filters'),
helpers: path.join(__dirname, '/workspace/utils/helpers'),
media: path.join(__dirname, '/workspace/media'),
middleware: path.join(__dirname, '/workspace/middleware'),
pages: path.join(__dirname, '/workspace/pages'),
partials: path.join(__dirname, '/workspace/partials'),
public: path.join(__dirname, '/workspace/public'),
routes: path.join(__dirname, '/workspace/routes'),
tokenWallets: path.join(__dirname, '/.wallet')
Expand Down Expand Up @@ -464,7 +417,7 @@ var conf = convict({
},
env: {
doc: 'The applicaton environment.',
format: ['production', 'development', 'test', 'qa'],
format: String,
default: 'development',
env: 'NODE_ENV',
arg: 'node_env'
Expand Down Expand Up @@ -517,6 +470,11 @@ var conf = convict({
format: Array,
default: []
}
},
engines: {
doc: 'Engine-specific configuration parameters',
format: Object,
default: {}
}
})

Expand Down
15 changes: 3 additions & 12 deletions config/config.development.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,12 @@
"workspace": "workspace",
"datasources": "workspace/datasources",
"pages": "workspace/pages",
"partials": "workspace/partials",
"events": "workspace/events",
"middleware": "workspace/middleware",
"media": "workspace/media",
"public": "workspace/public",
"routes": "workspace/routes",
"filters": "workspace/utils/filters",
"helpers": "workspace/utils/helpers"
"routes": "workspace/routes"
},
"allowJsonView": true,
"debug": true,
"dust": {
"cache": true,
"debug": true,
"debugLevel": "DEBUG",
"whitespace": true
}
}
"debug": true
}
5 changes: 1 addition & 4 deletions config/config.test.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
"workspace": "test/app",
"datasources": "test/app/datasources",
"pages": "test/app/pages",
"partials": "test/app/partials",
"events": "test/app/events",
"middleware": "test/app/middleware",
"media": "test/app/media",
"public": "test/app/public",
"routes": "test/app/routes",
"filters": "test/app/utils/filters",
"helpers": "test/app/utils/helpers"
"routes": "test/app/routes"
}
}
18 changes: 12 additions & 6 deletions dadi/lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,13 @@ Api.prototype.listener = function (req, res) {
try {
// if end of the stack, no middleware could handle the current
// request, so get matching routes from the loaded page components and
// add them to the stack after the cache handler but just before the
// 404 handler, then continue the loop
if (this.stack[stackIdx].name === 'cache' && !pathsLoaded) {
// add them to the stack just before the 404 handler, then continue the loop
// console.log(pathsLoaded, this.stack[stackIdx].name, this.stack[stackIdx+1] ? this.stack[stackIdx+1].name : 'nothing left!')
if (
this.stack[stackIdx + 1] &&
this.stack[stackIdx + 1].name === 'notFound' &&
!pathsLoaded
) {
// find path specific handlers
var hrstart = process.hrtime()

Expand Down Expand Up @@ -372,7 +376,8 @@ function onError (api) {
res.end(
errorView({
headline: 'Something went wrong.',
human: 'We apologise, but something is not working as it should. It is not something you did, but we cannot complete this right now.',
human:
'We apologise, but something is not working as it should. It is not something you did, but we cannot complete this right now.',
developer: data.message,
stack: data.stack,
statusCode: data.statusCode,
Expand All @@ -386,7 +391,7 @@ function onError (api) {

// return a 404
function notFound (api, req, res) {
return function () {
return function notFound () {
res.statusCode = 404

// look for a 404 page that has been loaded
Expand All @@ -401,7 +406,8 @@ function notFound (api, req, res) {
res.end(
errorView({
headline: 'Page not found.',
human: 'This page has either been moved, or it never existed at all. Sorry about that, this was not your fault.',
human:
'This page has either been moved, or it never existed at all. Sorry about that, this was not your fault.',
developer: 'HTTP Headers',
stack: JSON.stringify(req.headers, null, 2),
statusCode: '404',
Expand Down
9 changes: 6 additions & 3 deletions dadi/lib/controller/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

/**
* @module Controller
*/
Expand All @@ -24,7 +26,7 @@ var sendBackJSON = help.sendBackJSON
/**
*
*/
var Controller = function (page, options, meta) {
var Controller = function (page, options, meta, engine) {
if (!page) throw new Error('Page instance required')

Controller.numInstances = (Controller.numInstances || 0) + 1
Expand All @@ -34,6 +36,7 @@ var Controller = function (page, options, meta) {

this.options = options || {}
this.meta = meta || {}
this.engine = engine

this.datasources = {}
this.events = []
Expand Down Expand Up @@ -587,8 +590,8 @@ function processSearchParameters (key, datasource, req) {
datasource.processRequest(key, req)
}

module.exports = function (page, options, meta) {
return new Controller(page, options, meta)
module.exports = function (page, options, meta, engine) {
return new Controller(page, options, meta, engine)
}

module.exports.Controller = Controller
7 changes: 4 additions & 3 deletions dadi/lib/controller/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ var Router = function (server, options) {
this.handlers = []
this.rules = []

this.rewritesFile = config.get('rewrites.path') === ''
? null
: path.resolve(config.get('rewrites.path'))
this.rewritesFile =
config.get('rewrites.path') === ''
? null
: path.resolve(config.get('rewrites.path'))
this.rewritesDatasource = config.get('rewrites.datasource')
this.loadDatasourceAsFile = config.get('rewrites.loadDatasourceAsFile')

Expand Down
7 changes: 4 additions & 3 deletions dadi/lib/datasource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ Datasource.prototype.processRequest = function (datasource, req) {
req.params.hasOwnProperty(obj.param) && req.params[obj.param]

if (obj.field && paramValue) {
paramValue = obj.type === 'Number'
? Number(paramValue)
: encodeURIComponent(paramValue)
paramValue =
obj.type === 'Number'
? Number(paramValue)
: encodeURIComponent(paramValue)

if (obj.target === 'filter') {
// this.schema.datasource.filter[obj.field] = paramValue
Expand Down
Loading

0 comments on commit 1255df3

Please sign in to comment.