@nakedcreativity/cee-ms-node 0.3.0 → 0.3.1

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.
Files changed (2) hide show
  1. package/index.js +25 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -14,6 +14,7 @@ function ceems(config) {
14
14
  // // set up static file hosting
15
15
  this.app.use(express.static(config.assets))
16
16
  this.app.use(bodyParser.json());
17
+ this.app.use(bodyParser.urlencoded({extended:false}));
17
18
 
18
19
  this.engine = Liquid({
19
20
  root: path.resolve('./views/'), // for layouts and partials
@@ -90,6 +91,7 @@ function ceems(config) {
90
91
  res.header(header[0], header[1])
91
92
  })
92
93
  }
94
+
93
95
  next();
94
96
  });
95
97
 
@@ -102,11 +104,21 @@ function ceems(config) {
102
104
 
103
105
  this.app.post(/draft\/(.*)/, (req, res)=>{
104
106
 
107
+ console.log('received a POST')
105
108
  // validate authorisation JWT here
106
109
  this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
110
+
107
111
  //console.log(req.body.page)
108
112
  req.query.edit = true;
109
- this.render(req,res, req.body.page);
113
+
114
+ // this was sent by the iframe, handle it differently
115
+ console.log(req.query)
116
+ if(req.query.iframe != null){
117
+ console.log('using parsed body')
118
+ this.render(req, res, JSON.parse(decodeURIComponent(req.body.page)));
119
+ }else {
120
+ this.render(req, res, req.body.page);
121
+ }
110
122
 
111
123
  })
112
124
 
@@ -115,9 +127,11 @@ function ceems(config) {
115
127
  ceems.prototype.load = function(req, res){
116
128
 
117
129
  var path = req._parsedUrl.pathname
130
+ console.log(path)
118
131
  this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
119
132
  //this.pages_map = _.indexBy(this.site.pages, 'url');
120
133
 
134
+
121
135
  if(this.site.pages[path]){
122
136
  var page = this.site.pages[path]
123
137
 
@@ -128,7 +142,9 @@ ceems.prototype.load = function(req, res){
128
142
  var page = JSON.parse(fs.readFileSync('./pages/'+page._id+'.json', 'utf8'));
129
143
  return page
130
144
 
131
- }else{
145
+ }
146
+ // 404
147
+ else{
132
148
  console.log('404 for ',path)
133
149
  res.status(404).send('Sorry, this page does not exist');
134
150
  }
@@ -138,10 +154,16 @@ ceems.prototype.load = function(req, res){
138
154
 
139
155
  ceems.prototype.render = function(req, res, page=null) {
140
156
 
157
+ if(req.query.initial != null){
158
+ // validate JWT here
159
+ res.send('Waiting...')
160
+ return
161
+ }
162
+
141
163
  if(!page){
142
164
  page = this.load(req, res)
143
165
  }
144
-
166
+ console.log(page)
145
167
  // get any external data, and save this into the page
146
168
  if(page.external){
147
169
  _.each(page.external, function(ext, key){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakedcreativity/cee-ms-node",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {