From 72e9de96e4ff86101cd9957ca422dbb646985b61 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 13 Nov 2025 11:31:58 -0500 Subject: [PATCH] feat: Containerize application with Docker and improve admin error handling This commit introduces Docker support for the application to ensure a consistent and reproducible environment across different deployment targets. - Added for building a Docker image of the application. - Added to exclude unnecessary files from the Docker image. - Improved error handling in to provide more descriptive messages when the server returns an unexpected response, aiding in debugging. - Included changes, likely from local testing. --- .dockerignore | 8 ++++++++ Dockerfile | 20 ++++++++++++++++++++ admin.js | 12 ++++++++++-- update.json | 4 ++-- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d75e453 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +# Ignore dependencies, git, and local development files +node_modules +.git +.gitignore +.env +Dockerfile +.dockerignore +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..38e6708 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Use an official Node.js runtime as a parent image +FROM node:18-alpine + +# Set the working directory in the container +WORKDIR /usr/src/app + +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ + +# Install any needed packages +RUN npm install + +# Bundle app source +COPY . . + +# Make port 3050 available to the world outside this container +EXPOSE 3050 + +# Define the command to run the app +CMD [ "node", "server.js" ] diff --git a/admin.js b/admin.js index 6aae5cb..432c451 100644 --- a/admin.js +++ b/admin.js @@ -84,7 +84,15 @@ document.addEventListener('DOMContentLoaded', () => { }, body: JSON.stringify({ password: password, data: newUpdateData }), }) - .then(response => response.json()) + .then(response => { + const contentType = response.headers.get('content-type'); + if (response.ok && contentType && contentType.includes('application/json')) { + return response.json(); + } + return response.text().then(text => { + throw new Error(`Server response was not OK or not JSON. Status: ${response.status}. Body: ${text}`); + }); + }) .then(result => { if (result.success) { showFeedback('Success! The store status has been updated.', 'is-success'); @@ -96,7 +104,7 @@ document.addEventListener('DOMContentLoaded', () => { }) .catch(error => { console.error('Error sending update:', error); - showFeedback('An error occurred. Check the console and make sure the server is running.', 'is-danger'); + showFeedback(error.message, 'is-danger'); }) .finally(() => { // Hide loading state diff --git a/update.json b/update.json index d02343b..be9c6fe 100644 --- a/update.json +++ b/update.json @@ -1,7 +1,7 @@ [ { - "message": "", - "isClosed": true, + "message": "test", + "isClosed": false, "closedMessage": "We are temporarily closed. Please check back later for updates." } ] \ No newline at end of file