@nakedcreativity/cee-ms-node 0.2.1 → 0.2.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 +37 -25
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -66,11 +66,11 @@ function ceems(config) {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
69
|
+
if(!config.customHandler){
|
|
70
|
+
this.app.get(/(.*)/, (req, res)=>{
|
|
71
|
+
this.render(req,res);
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
74
|
|
|
75
75
|
this.app.post(/draft\/(.*)/, (req, res)=>{
|
|
76
76
|
|
|
@@ -84,36 +84,48 @@ function ceems(config) {
|
|
|
84
84
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
ceems.prototype.
|
|
87
|
+
ceems.prototype.load = function(path){
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.pages_map = _.indexBy(this.site.pages, 'url');
|
|
89
|
+
this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
|
|
90
|
+
this.pages_map = _.indexBy(this.site.pages, 'url');
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
if(this.pages_map[path]){
|
|
93
|
+
var page = this.pages_map[path]
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
if(page.redirect){
|
|
96
|
+
res.redirect(parseInt(page.redirect.type), page.redirect.to)
|
|
97
|
+
}
|
|
99
98
|
|
|
100
|
-
|
|
99
|
+
var page = JSON.parse(fs.readFileSync('./pages/'+page.handle+'.json', 'utf8'));
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
return page
|
|
102
|
+
|
|
103
|
+
}else{
|
|
104
|
+
console.log('404 for ',path)
|
|
105
|
+
res.status(404).send('Sorry, this page does not exist');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
ceems.prototype.render = function(req, res, page=null) {
|
|
112
|
+
|
|
113
|
+
if(!page){
|
|
114
|
+
this.load(req._parsedUrl.pathname)
|
|
105
115
|
}
|
|
106
116
|
|
|
107
117
|
// get any external data, and save this into the page
|
|
108
|
-
|
|
118
|
+
if(page.external){
|
|
119
|
+
_.each(page.external, function(ext, key){
|
|
109
120
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
try {
|
|
122
|
+
page.external[key].data = JSON.parse(fs.readFileSync('./'+ext.file, 'utf8'));
|
|
123
|
+
}catch(error){
|
|
124
|
+
console.log(error)
|
|
125
|
+
}
|
|
115
126
|
|
|
116
|
-
|
|
127
|
+
})
|
|
128
|
+
}
|
|
117
129
|
|
|
118
130
|
var renderedRegions = {}
|
|
119
131
|
var jobs = []
|