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.
This commit is contained in:
chris 2025-11-13 11:31:58 -05:00
parent 91885d5ff5
commit 72e9de96e4
4 changed files with 40 additions and 4 deletions

8
.dockerignore Normal file
View File

@ -0,0 +1,8 @@
# Ignore dependencies, git, and local development files
node_modules
.git
.gitignore
.env
Dockerfile
.dockerignore
README.md

20
Dockerfile Normal file
View File

@ -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" ]

View File

@ -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

View File

@ -1,7 +1,7 @@
[
{
"message": "",
"isClosed": true,
"message": "test",
"isClosed": false,
"closedMessage": "We are temporarily closed. Please check back later for updates."
}
]