@nakedcreativity/cee-ms-node 0.2.6 → 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 +33 -11
  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,33 +104,47 @@ 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
 
113
125
  }
114
126
 
115
- ceems.prototype.load = function(path){
127
+ ceems.prototype.load = function(req, res){
116
128
 
129
+ var path = req._parsedUrl.pathname
130
+ console.log(path)
117
131
  this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
118
- this.pages_map = _.indexBy(this.site.pages, 'url');
119
-
120
- if(this.pages_map[path]){
121
- var page = this.pages_map[path]
132
+ //this.pages_map = _.indexBy(this.site.pages, 'url');
133
+
134
+
135
+ if(this.site.pages[path]){
136
+ var page = this.site.pages[path]
122
137
 
123
138
  if(page.redirect){
124
139
  res.redirect(parseInt(page.redirect.type), page.redirect.to)
125
140
  }
126
141
 
127
- var page = JSON.parse(fs.readFileSync('./pages/'+page.handle+'.json', 'utf8'));
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(path){
138
154
 
139
155
  ceems.prototype.render = function(req, res, page=null) {
140
156
 
141
- if(!page){
142
- page = this.load(req._parsedUrl.pathname)
157
+ if(req.query.initial != null){
158
+ // validate JWT here
159
+ res.send('Waiting...')
160
+ return
143
161
  }
144
162
 
163
+ if(!page){
164
+ page = this.load(req, res)
165
+ }
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.2.6",
3
+ "version": "0.3.1",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {