@nakedcreativity/cee-ms-node 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +29 -30
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4,8 +4,7 @@ const fs = require('fs');
|
|
|
4
4
|
const _ = require('underscore');
|
|
5
5
|
var Liquid = require('nakedcreativity-liquid');
|
|
6
6
|
var cheerio = require('cheerio');
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
var bodyParser = require("body-parser");
|
|
9
8
|
|
|
10
9
|
function ceems(config) {
|
|
11
10
|
|
|
@@ -14,6 +13,7 @@ function ceems(config) {
|
|
|
14
13
|
// process config and set defaults
|
|
15
14
|
// // set up static file hosting
|
|
16
15
|
this.app.use(express.static(config.assets))
|
|
16
|
+
this.app.use(bodyParser.json());
|
|
17
17
|
|
|
18
18
|
this.engine = Liquid({
|
|
19
19
|
root: path.resolve('./views/'), // for layouts and partials
|
|
@@ -67,36 +67,39 @@ function ceems(config) {
|
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
this.app.get(/(.*)/, (req, res)=>{
|
|
70
|
-
this.auto(req,res);
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
}
|
|
74
70
|
|
|
75
|
-
|
|
71
|
+
this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
|
|
72
|
+
this.pages_map = _.indexBy(this.site.pages, 'url');
|
|
76
73
|
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
if(this.pages_map[req._parsedUrl.pathname]){
|
|
75
|
+
var page = this.pages_map[req._parsedUrl.pathname]
|
|
79
76
|
|
|
80
|
-
|
|
77
|
+
if(page.redirect){
|
|
78
|
+
res.redirect(parseInt(page.redirect.type), page.redirect.to)
|
|
79
|
+
}
|
|
81
80
|
|
|
82
|
-
|
|
83
|
-
var page = this.pages_map[req._parsedUrl.pathname]
|
|
81
|
+
var page = JSON.parse(fs.readFileSync('./pages/'+page.handle+'.json', 'utf8'));
|
|
84
82
|
|
|
85
|
-
|
|
86
|
-
res.
|
|
83
|
+
}else{
|
|
84
|
+
res.status(404).send('Sorry, this page does not exist');
|
|
87
85
|
}
|
|
86
|
+
|
|
87
|
+
this.render(page,req,res);
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
})
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
91
|
+
this.app.post(/draft\/(.*)/, (req, res)=>{
|
|
92
|
+
|
|
93
|
+
// validate authorisation JWT here
|
|
94
|
+
this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
|
|
95
|
+
this.render(req.body.page,req,res);
|
|
96
|
+
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
ceems.prototype.render = function(page, req, res) {
|
|
98
102
|
|
|
99
|
-
|
|
100
103
|
// get any external data, and save this into the page
|
|
101
104
|
_.each(page.external, function(ext, key){
|
|
102
105
|
|
|
@@ -196,10 +199,8 @@ ceems.prototype.auto = function(req, res) {
|
|
|
196
199
|
if(err){
|
|
197
200
|
console.log(err)
|
|
198
201
|
}
|
|
199
|
-
|
|
200
|
-
console.log(
|
|
201
|
-
console.log('..................')
|
|
202
|
-
res.header('X-FRAME-OPTIONS', 'ALLOW-FROM localhost:3006');
|
|
202
|
+
//res.header('X-FRAME-OPTIONS', 'allow-from http://localhost:3002');
|
|
203
|
+
console.log(res)
|
|
203
204
|
res.send(html)
|
|
204
205
|
})
|
|
205
206
|
|
|
@@ -214,13 +215,11 @@ ceems.prototype.auto = function(req, res) {
|
|
|
214
215
|
ceems.prototype.init = function(){
|
|
215
216
|
|
|
216
217
|
// needs to be dealt with on each request, or results cache in someway
|
|
217
|
-
|
|
218
|
-
|
|
219
218
|
|
|
220
219
|
}
|
|
221
220
|
|
|
222
221
|
ceems.prototype.viewsPath = function(){
|
|
223
222
|
return './views/'
|
|
224
|
-
}
|
|
223
|
+
}
|
|
225
224
|
|
|
226
225
|
module.exports = ceems;
|