Last active
September 7, 2024 15:55
-
-
Save abeisgoat/40b8e0e47f753cc69559d3c4fe1d6962 to your computer and use it in GitHub Desktop.
Firebase Storage + Imgix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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