Skip to content

Commit

Permalink
fix: add check for binary files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Oct 26, 2019
1 parent 4a6a25f commit b201222
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/cli/create/template/apps/site/handler/handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require("fs");
const path = require("path");
const mime = require("mime-types");
const isUtf8 = require("isutf8");

const createResponse = ({ type, body, isBase64Encoded, headers }) => {
return {
Expand All @@ -20,7 +21,7 @@ module.exports.handler = async event => {
let type = mime.lookup(key);
let isBase64Encoded = false;

if(key.endsWith("undefined")) {
if (key.endsWith("undefined")) {
return createResponse({
type,
body: "",
Expand All @@ -43,8 +44,6 @@ module.exports.handler = async event => {

const filePath = path.resolve(key);

// TODO: check if file should be base64 encoded (binary files)

try {
let buffer = await new Promise((resolve, reject) => {
fs.readFile(filePath, (err, data) => {
Expand All @@ -53,6 +52,7 @@ module.exports.handler = async event => {
});
});

isBase64Encoded = !isUtf8(buffer);
const headers = {};

if (key.includes("static")) {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/create/template/apps/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"cross-fetch": "^3.0.2",
"dotenv": "^8.1.0",
"env-cmd": "^9.0.3",
"isutf8": "^2.1.0",
"react-apollo": "^3.1.0",
"react-app-env": "^1.2.3",
"react-helmet": "^5.2.0",
Expand Down

0 comments on commit b201222

Please sign in to comment.