Skip to content

Commit

Permalink
feat: Add /api/ping endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wryonik committed Sep 19, 2024
1 parent 8ce5a9a commit 2ba1443
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 29 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -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}`);
});

0 comments on commit 2ba1443

Please sign in to comment.