Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:18-alpine

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install --only=production

COPY . .

EXPOSE 3000

CMD ["node", "app.js"]
35 changes: 14 additions & 21 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
const express = require('express');
const express = require("express");
const app = express();
const hostname = '127.0.0.1'; // Your server ip address
const port = 3000;

const version = '1.0.0';
// Health check route for ECS
app.get("/health", (req, res) => {
res.status(200).send("OK");
});

app.get('/', (req, res) => {
// set response content
res.send(`<html>
<body>
<h1 style="color:blue;text-align: center;margin-top: 100px;"> [Version ${version}]: This is AMAZING!!! Like & Subscribe!</h1>
<div style="position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%)">
<img src="https://picsum.photos/400/400?random=1">
</div>
</body>
</html>`);

console.log(`[Version ${version}]: New request => http://${hostname}:${port}`+req.url);
// Root route
app.get("/", (req, res) => {
res.send("Hello from Node.js running on ECS EC2 (port 3000)!");
});

})

app.listen(port, () => {
console.log(`[Version ${version}]: Server running at http://${hostname}:${port}/`);
})
// Start server
const PORT = process.env.PORT || 3000;
app.listen(PORT, "0.0.0.0", () => {
console.log(`🚀 Server running on http://0.0.0.0:${PORT}`);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
"dependencies": {
"express": "^4.18.2"
}
}
}