@nakedcreativity/cee-ms-node 0.2.2 → 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 +33 -20
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -65,6 +65,7 @@ function ceems(config) {
|
|
|
65
65
|
next();
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
+
|
|
68
69
|
if(!config.customHandler){
|
|
69
70
|
this.app.get(/(.*)/, (req, res)=>{
|
|
70
71
|
this.render(req,res);
|
|
@@ -83,36 +84,48 @@ function ceems(config) {
|
|
|
83
84
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
ceems.prototype.
|
|
87
|
+
ceems.prototype.load = function(path){
|
|
87
88
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
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');
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
if(this.pages_map[path]){
|
|
93
|
+
var page = this.pages_map[path]
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
if(page.redirect){
|
|
96
|
+
res.redirect(parseInt(page.redirect.type), page.redirect.to)
|
|
97
|
+
}
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
var page = JSON.parse(fs.readFileSync('./pages/'+page.handle+'.json', 'utf8'));
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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)
|
|
104
115
|
}
|
|
105
116
|
|
|
106
117
|
// get any external data, and save this into the page
|
|
107
|
-
|
|
118
|
+
if(page.external){
|
|
119
|
+
_.each(page.external, function(ext, key){
|
|
108
120
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
121
|
+
try {
|
|
122
|
+
page.external[key].data = JSON.parse(fs.readFileSync('./'+ext.file, 'utf8'));
|
|
123
|
+
}catch(error){
|
|
124
|
+
console.log(error)
|
|
125
|
+
}
|
|
114
126
|
|
|
115
|
-
|
|
127
|
+
})
|
|
128
|
+
}
|
|
116
129
|
|
|
117
130
|
var renderedRegions = {}
|
|
118
131
|
var jobs = []
|