@nakedcreativity/cee-ms-node 0.3.0 → 0.3.2

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 +15 -4
  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
 
@@ -104,9 +106,16 @@ function ceems(config) {
104
106
 
105
107
  // validate authorisation JWT here
106
108
  this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
109
+
107
110
  //console.log(req.body.page)
108
111
  req.query.edit = true;
109
- this.render(req,res, req.body.page);
112
+
113
+ // if this was sent by the iframe, handle it differently
114
+ if(req.query.iframe != null){
115
+ this.render(req, res, JSON.parse(decodeURIComponent(req.body.page)));
116
+ }else {
117
+ this.render(req, res, req.body.page);
118
+ }
110
119
 
111
120
  })
112
121
 
@@ -114,10 +123,11 @@ function ceems(config) {
114
123
 
115
124
  ceems.prototype.load = function(req, res){
116
125
 
117
- var path = req._parsedUrl.pathname
126
+ var path = req._parsedUrl.pathname.substring(1)
118
127
  this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
119
128
  //this.pages_map = _.indexBy(this.site.pages, 'url');
120
129
 
130
+
121
131
  if(this.site.pages[path]){
122
132
  var page = this.site.pages[path]
123
133
 
@@ -128,7 +138,9 @@ ceems.prototype.load = function(req, res){
128
138
  var page = JSON.parse(fs.readFileSync('./pages/'+page._id+'.json', 'utf8'));
129
139
  return page
130
140
 
131
- }else{
141
+ }
142
+ // 404
143
+ else{
132
144
  console.log('404 for ',path)
133
145
  res.status(404).send('Sorry, this page does not exist');
134
146
  }
@@ -141,7 +153,6 @@ ceems.prototype.render = function(req, res, page=null) {
141
153
  if(!page){
142
154
  page = this.load(req, res)
143
155
  }
144
-
145
156
  // get any external data, and save this into the page
146
157
  if(page.external){
147
158
  _.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.2",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {