@nakedcreativity/cee-ms-node 0.1.3 → 0.2.0
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 +34 -28
- 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,43 @@ function ceems(config) {
|
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
this.app.get(/(.*)/, (req, res)=>{
|
|
70
|
-
|
|
70
|
+
|
|
71
|
+
this.render(req,res, page);
|
|
72
|
+
|
|
71
73
|
})
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
this.app.post(/draft\/(.*)/, (req, res)=>{
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
// validate authorisation JWT here
|
|
78
|
+
this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
|
|
79
|
+
console.log(req.body.page)
|
|
80
|
+
req.query.edit = true;
|
|
81
|
+
this.render(req,res, req.body.page);
|
|
76
82
|
|
|
77
|
-
|
|
78
|
-
this.pages_map = _.indexBy(this.site.pages, 'url');
|
|
83
|
+
})
|
|
79
84
|
|
|
80
|
-
|
|
85
|
+
}
|
|
81
86
|
|
|
82
|
-
|
|
83
|
-
var page = this.pages_map[req._parsedUrl.pathname]
|
|
87
|
+
ceems.prototype.render = function(req, res, page=null) {
|
|
84
88
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
if(!page){
|
|
90
|
+
this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
|
|
91
|
+
this.pages_map = _.indexBy(this.site.pages, 'url');
|
|
88
92
|
|
|
89
|
-
|
|
93
|
+
if(this.pages_map[req._parsedUrl.pathname]){
|
|
94
|
+
var page = this.pages_map[req._parsedUrl.pathname]
|
|
90
95
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
if(page.redirect){
|
|
97
|
+
res.redirect(parseInt(page.redirect.type), page.redirect.to)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var page = JSON.parse(fs.readFileSync('./pages/'+page.handle+'.json', 'utf8'));
|
|
101
|
+
|
|
102
|
+
}else{
|
|
95
103
|
res.status(404).send('Sorry, this page does not exist');
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
|
|
99
|
-
|
|
100
107
|
// get any external data, and save this into the page
|
|
101
108
|
_.each(page.external, function(ext, key){
|
|
102
109
|
|
|
@@ -135,7 +142,10 @@ ceems.prototype.auto = function(req, res) {
|
|
|
135
142
|
var $ = cheerio.load(html);
|
|
136
143
|
|
|
137
144
|
$.root().children().attr('data-module-type', module.type);
|
|
138
|
-
|
|
145
|
+
if(module._id){
|
|
146
|
+
$.root().children().attr('data-module-id', module._id);
|
|
147
|
+
}
|
|
148
|
+
|
|
139
149
|
|
|
140
150
|
html = $.html()
|
|
141
151
|
}
|
|
@@ -168,7 +178,7 @@ ceems.prototype.auto = function(req, res) {
|
|
|
168
178
|
if(req.query.edit != null){
|
|
169
179
|
var $ = cheerio.load(html);
|
|
170
180
|
$.root().children().attr('data-module-type', module.type);
|
|
171
|
-
$.root().children().attr('data-module-id', module.
|
|
181
|
+
$.root().children().attr('data-module-id', module._id);
|
|
172
182
|
//console.log($.root().children())
|
|
173
183
|
|
|
174
184
|
html = $.html()
|
|
@@ -196,10 +206,8 @@ ceems.prototype.auto = function(req, res) {
|
|
|
196
206
|
if(err){
|
|
197
207
|
console.log(err)
|
|
198
208
|
}
|
|
199
|
-
|
|
200
|
-
console.log(
|
|
201
|
-
console.log('..................')
|
|
202
|
-
res.header('X-FRAME-OPTIONS', 'ALLOW-FROM localhost:3006');
|
|
209
|
+
//res.header('X-FRAME-OPTIONS', 'allow-from http://localhost:3002');
|
|
210
|
+
//console.log(res)
|
|
203
211
|
res.send(html)
|
|
204
212
|
})
|
|
205
213
|
|
|
@@ -214,13 +222,11 @@ ceems.prototype.auto = function(req, res) {
|
|
|
214
222
|
ceems.prototype.init = function(){
|
|
215
223
|
|
|
216
224
|
// needs to be dealt with on each request, or results cache in someway
|
|
217
|
-
|
|
218
|
-
|
|
219
225
|
|
|
220
226
|
}
|
|
221
227
|
|
|
222
228
|
ceems.prototype.viewsPath = function(){
|
|
223
229
|
return './views/'
|
|
224
|
-
}
|
|
230
|
+
}
|
|
225
231
|
|
|
226
232
|
module.exports = ceems;
|