Skip to content

Instantly share code, notes, and snippets.

@abeisgoat
Last active July 19, 2016 19:18
Show Gist options
  • Save abeisgoat/40b8e0e47f753cc69559d3c4fe1d6962 to your computer and use it in GitHub Desktop.
Save abeisgoat/40b8e0e47f753cc69559d3c4fe1d6962 to your computer and use it in GitHub Desktop.
Firebase Storage + Imgix
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Imgix / Firebase Storage</title>
<script src="https://www.gstatic.com/firebasejs/3.2.0/firebase.js"></script>
<script>
var IMGIX_REDIRECT_URL = "";
var config = {
//...
};
firebase.initializeApp(config);
var storage = firebase.storage();
var storageRef = storage.ref();
var imageRef = storageRef.child('sunset.jpg');
var imgixParameters = "w=400&padding=10";
imageRef.getDownloadURL().then(function(url) {
document.getElementById("imgix").setAttribute("src", IMGIX_REDIRECT_URL + "?url=" + url + "&" + imgixParameters)
});
</script>
</head>
<body>
<img id="imgix"></img>
</body>
</html>
var ImgixClient = require('imgix-core-js');
require('string.prototype.startswith');
var IMGIX_HOST = ""; //"*.imgix.net";
var IMGIX_TOKEN = ""; // Secure Imgix Token
var FIREBASE_APP_NAME = ""; // The * in *.firebaseio.com
exports.imgixRedirect = function imgixRedirect (req, res) {
var incomingUrl, imgixUrl, imgixClient, imgixQuery;
incomingUrl = req.query.url;
if (!incomingUrl.startsWith("https://firebasestorage.googleapis.com/v0/b/" + FIREBASE_APP_NAME + ".appspot.com")) {
return res.status(400);
} else {
imgixQuery = req.query;
delete imgixQuery.url;
imgixClient = new ImgixClient({
host: IMGIX_HOST,
secureURLToken: IMGIX_TOKEN
});
imgixUrl = imgixClient.buildURL(incomingUrl, imgixQuery);
res.redirect(imgixUrl);
}
};
{
"name": "imgix-and-firebase-storage",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"imgix-core-js": "^1.0.3",
"string.prototype.startswith": "^0.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment