forked from iwilliams/ember-emblr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (37 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* jshint node: true */
'use strict';
var fs = require('fs');
var request = require('request');
module.exports = {
name: 'ember-emblr',
//included: function(app, parentAddon) {
//var target = (parentAddon || app);
// Now you can modify the app / parentAddon. For example, if you wanted
// to include a custom preprocessor, you could add it to the target's
// registry:
//
// target.registry.add('js', myPreprocessor);
//},
contentFor: function(type, config) {
if(type === 'body-footer' && config.environment === 'production') {
return fs.readFileSync(__dirname + '/addon/tumblr-posts.htm').toString();
}
},
// We use this hook to act as a proxy so we can get around CORS in development
serverMiddleware: function(config) {
var self = this;
var app = config.app;
var options = config.options;
var project = options.project;
var appConfig = project.config(options.environment);
app.get(options.baseURL + 'tumblr-mock*', function(req, res, next) {
var url = "http://" + appConfig.tumblr + ".tumblr.com" + req.path.substr("/tumblr-mock".length);
request(url, function(error, response, body) {
if (!error && response.statusCode == 200) {
res.contentType('text/html');
res.send(body);
}
});
});
}
};