From 5f4d5049e09d0b692328b51e26d80a463c7a77fa Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Tue, 14 Dec 2021 01:35:58 -0700 Subject: [PATCH] Properly handle empty/missing custom JS/HTML --- hyperglass/ui/pages/_document.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hyperglass/ui/pages/_document.tsx b/hyperglass/ui/pages/_document.tsx index 8865bde..ab3053d 100644 --- a/hyperglass/ui/pages/_document.tsx +++ b/hyperglass/ui/pages/_document.tsx @@ -13,8 +13,14 @@ interface DocumentExtra extends DocumentInitialProps { class MyDocument extends Document { static async getInitialProps(ctx: DocumentContext): Promise { const initialProps = await Document.getInitialProps(ctx); - const customJs = fs.readFileSync('custom.js').toString(); - const customHtml = fs.readFileSync('custom.html').toString(); + let customJs = '', + customHtml = ''; + if (fs.existsSync('custom.js')) { + customJs = fs.readFileSync('custom.js').toString(); + } + if (fs.existsSync('custom.html')) { + customHtml = fs.readFileSync('custom.html').toString(); + } return { customJs, customHtml, ...initialProps }; }