Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Update to allow CORS access
Browse files Browse the repository at this point in the history
  • Loading branch information
ifahrentholz committed Dec 21, 2017
1 parent 77670b2 commit bcb509f
Show file tree
Hide file tree
Showing 3 changed files with 3,581 additions and 9 deletions.
13 changes: 8 additions & 5 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ module.exports = function(config) {
var app = express();
var imageService = require('./services/image-service');


app.all('/*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});

app.get('/' + config.namespace + '/:dimension.:contentType', function(req, res, next) {
var p = req.params;
var q = req.query;
Expand All @@ -20,17 +27,14 @@ module.exports = function(config) {
maxAge: q.maxAge,
expiryDate: q.expiryDate
});

imageService.createImage(_config, function(err, image) {
if(err) {
return console.log(err);
}

res.setHeader('Content-Type', 'image/' + _config.contentType);
res.setHeader('Cache-Control', 'public, max-age=' + _config.maxAge);
res.setHeader('Expires', _config.expiryDate);
res.setHeader('Last-Modified', _config.expiryDate);

if(_config.delay) {
setTimeout(function() {
res.send(image);
Expand All @@ -39,10 +43,9 @@ module.exports = function(config) {
else {
res.send(image);
}

})

});


return app;
};
Loading

0 comments on commit bcb509f

Please sign in to comment.