From 111760a7f0421a982a524f51e1eea55714c6af50 Mon Sep 17 00:00:00 2001 From: jonmeow <46229924+jonmeow@users.noreply.github.com> Date: Wed, 20 May 2020 18:04:40 -0700 Subject: [PATCH] Fix mime types of responses. --- src/firebase/functions/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/firebase/functions/index.js b/src/firebase/functions/index.js index 3b334a5d492f4..f703b62725087 100644 --- a/src/firebase/functions/index.js +++ b/src/firebase/functions/index.js @@ -11,6 +11,7 @@ admin.initializeApp(); const cookieParser = require('cookie-parser')(); const cors = require('cors')({origin: true}); +const path = require('path'); const express = require('express'); const app = express(); @@ -86,13 +87,14 @@ app.use(validateFirebaseIdToken); app.get('*', (req, res) => { // Remove the prefix /, and default to index.html. - var path = req.path.replace(/^(\/)/, ""); - if (path === "") { - path = "index.html"; + var file = req.path.replace(/^(\/)/, ""); + if (file === "") { + file = "index.html"; } + res.type(path.extname(file)); // Serve the requested data from the carbon-lang bucket. const bucket = gcs.bucket("gs://www.carbon-lang.dev"); - const stream = bucket.file(path).createReadStream(); + const stream = bucket.file(file).createReadStream(); //stream.on('error', function(err) { res.status(404).send(err.message); }); stream.on('error', function(err) { console.log(err.message);