@nakedcreativity/cee-ms-node 0.3.1 → 0.3.3
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 +7 -18
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -104,17 +104,13 @@ function ceems(config) {
|
|
|
104
104
|
|
|
105
105
|
this.app.post(/draft\/(.*)/, (req, res)=>{
|
|
106
106
|
|
|
107
|
-
console.log('received a POST')
|
|
108
107
|
// validate authorisation JWT here
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
|
|
111
109
|
//console.log(req.body.page)
|
|
112
110
|
req.query.edit = true;
|
|
113
111
|
|
|
114
|
-
// this was sent by the iframe, handle it differently
|
|
115
|
-
console.log(req.query)
|
|
112
|
+
// if this was sent by the iframe, handle it differently
|
|
116
113
|
if(req.query.iframe != null){
|
|
117
|
-
console.log('using parsed body')
|
|
118
114
|
this.render(req, res, JSON.parse(decodeURIComponent(req.body.page)));
|
|
119
115
|
}else {
|
|
120
116
|
this.render(req, res, req.body.page);
|
|
@@ -126,8 +122,7 @@ function ceems(config) {
|
|
|
126
122
|
|
|
127
123
|
ceems.prototype.load = function(req, res){
|
|
128
124
|
|
|
129
|
-
var path = req._parsedUrl.pathname
|
|
130
|
-
console.log(path)
|
|
125
|
+
var path = req._parsedUrl.pathname.substring(1)
|
|
131
126
|
this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
|
|
132
127
|
//this.pages_map = _.indexBy(this.site.pages, 'url');
|
|
133
128
|
|
|
@@ -154,16 +149,9 @@ ceems.prototype.load = function(req, res){
|
|
|
154
149
|
|
|
155
150
|
ceems.prototype.render = function(req, res, page=null) {
|
|
156
151
|
|
|
157
|
-
if(req.query.initial != null){
|
|
158
|
-
// validate JWT here
|
|
159
|
-
res.send('Waiting...')
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
|
|
163
152
|
if(!page){
|
|
164
153
|
page = this.load(req, res)
|
|
165
154
|
}
|
|
166
|
-
console.log(page)
|
|
167
155
|
// get any external data, and save this into the page
|
|
168
156
|
if(page.external){
|
|
169
157
|
_.each(page.external, function(ext, key){
|
|
@@ -204,9 +192,10 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
204
192
|
// to-do: we need to give module access to entire page object, and therefore the 'sitemap' and other site information
|
|
205
193
|
var scope = module.content
|
|
206
194
|
scope.page = page
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
195
|
+
if (this.site){
|
|
196
|
+
scope.site = this.site.site
|
|
197
|
+
scope.pages = this.site.pages
|
|
198
|
+
}
|
|
210
199
|
this.engine.parseAndRender(moduleTemplate, scope)
|
|
211
200
|
.then(function(html){
|
|
212
201
|
|