From 2ba1443db10b8bfb6638c658bf72567103e6c066 Mon Sep 17 00:00:00 2001 From: Shubham Gupta Date: Thu, 19 Sep 2024 14:17:48 +0530 Subject: [PATCH] feat: Add /api/ping endpoint --- Dockerfile | 9 +++++---- package.json | 1 + server.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 server.js diff --git a/Dockerfile b/Dockerfile index 09b3a62..00506ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,10 +24,11 @@ RUN yarn build FROM nginx:alpine # Copy the built application from the build stage -COPY --from=build /app/dist /usr/share/nginx/html +COPY --from=build /app/dist ./build +COPY --from=build /app/server.js ./ -# Expose port 80 for the application +# Expose port 80 EXPOSE 80 -# Start Nginx server -CMD ["nginx", "-g", "daemon off;"] +# Start the server +CMD ["node", "server.js"] diff --git a/package.json b/package.json index a6090cf..caadca4 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "connectkit": "^1.7.3", "ethers": "^6.11.1", "permissionless": "^0.1.36", + "express": "^4.18.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-hot-toast": "^2.4.1", diff --git a/server.js b/server.js new file mode 100644 index 0000000..3595478 --- /dev/null +++ b/server.js @@ -0,0 +1,29 @@ +// server.js +import express from 'express'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const app = express(); +const PORT = process.env.PORT || 80; + +// Get the directory name of the current module +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +// Serve the React app's static files +app.use(express.static(path.join(__dirname, 'build'))); + +// Define the /api/ping endpoint +app.get('/api/ping', (req, res) => { + res.status(200).send('Hello world'); +}); + +// Handle any other routes and serve the React app +app.get('*', (req, res) => { + res.sendFile(path.join(__dirname, 'build', 'index.html')); +}); + +// Start the server +app.listen(PORT, () => { + console.log(`Server is running on port ${PORT}`); +});