@nakedcreativity/cee-ms-node 0.1.3 → 0.1.4

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 +29 -30
  2. 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,39 @@ function ceems(config) {
67
67
 
68
68
 
69
69
  this.app.get(/(.*)/, (req, res)=>{
70
- this.auto(req,res);
71
- })
72
-
73
- }
74
70
 
75
- ceems.prototype.auto = function(req, res) {
71
+ this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
72
+ this.pages_map = _.indexBy(this.site.pages, 'url');
76
73
 
77
- this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
78
- this.pages_map = _.indexBy(this.site.pages, 'url');
74
+ if(this.pages_map[req._parsedUrl.pathname]){
75
+ var page = this.pages_map[req._parsedUrl.pathname]
79
76
 
80
- var start = Date.now()
77
+ if(page.redirect){
78
+ res.redirect(parseInt(page.redirect.type), page.redirect.to)
79
+ }
81
80
 
82
- if(this.pages_map[req._parsedUrl.pathname]){
83
- var page = this.pages_map[req._parsedUrl.pathname]
81
+ var page = JSON.parse(fs.readFileSync('./pages/'+page.handle+'.json', 'utf8'));
84
82
 
85
- if(page.redirect){
86
- res.redirect(parseInt(page.redirect.type), page.redirect.to)
83
+ }else{
84
+ res.status(404).send('Sorry, this page does not exist');
87
85
  }
86
+
87
+ this.render(page,req,res);
88
88
 
89
- var page = JSON.parse(fs.readFileSync('./pages/'+page.handle+'.json', 'utf8'));
89
+ })
90
90
 
91
- }else{
92
- try {
93
- var page = JSON.parse(fs.readFileSync('./drafts/'+req._parsedUrl.pathname.replace('/drafts/','')+'.json', 'utf8'));
94
- }catch (error){
95
- res.status(404).send('Sorry, this page does not exist');
96
- }
97
- }
91
+ this.app.post(/draft\/(.*)/, (req, res)=>{
92
+
93
+ // validate authorisation JWT here
94
+ this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
95
+ this.render(req.body.page,req,res);
96
+
97
+ })
98
+
99
+ }
100
+
101
+ ceems.prototype.render = function(page, req, res) {
98
102
 
99
-
100
103
  // get any external data, and save this into the page
101
104
  _.each(page.external, function(ext, key){
102
105
 
@@ -196,10 +199,8 @@ ceems.prototype.auto = function(req, res) {
196
199
  if(err){
197
200
  console.log(err)
198
201
  }
199
- var finish = Date.now()
200
- console.log(finish - start, 'render time')
201
- console.log('..................')
202
- res.header('X-FRAME-OPTIONS', 'ALLOW-FROM localhost:3006');
202
+ //res.header('X-FRAME-OPTIONS', 'allow-from http://localhost:3002');
203
+ console.log(res)
203
204
  res.send(html)
204
205
  })
205
206
 
@@ -214,13 +215,11 @@ ceems.prototype.auto = function(req, res) {
214
215
  ceems.prototype.init = function(){
215
216
 
216
217
  // needs to be dealt with on each request, or results cache in someway
217
-
218
-
219
218
 
220
219
  }
221
220
 
222
221
  ceems.prototype.viewsPath = function(){
223
222
  return './views/'
224
- }
223
+ }
225
224
 
226
225
  module.exports = ceems;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakedcreativity/cee-ms-node",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {