Skip to content

Commit

Permalink
feat: build docker
Browse files Browse the repository at this point in the history
  • Loading branch information
tericcabrel committed Apr 2, 2023
1 parent cd4c751 commit fc7a299
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions node-ip-address/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:18-alpine3.17

RUN mkdir -p /home/app

WORKDIR /home/app

COPY build ./build
COPY package.json .

RUN yarn install --frozen-lockfile --production

EXPOSE 4500

ENTRYPOINT ["node", "build/index.js"]
3 changes: 3 additions & 0 deletions node-ip-address/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ yarn install
yarn start
```
The application will be launched by [Nodemon](https://nodemon.com) so it's will restart automatically on file change

# docker run -d -p 4500:4500 --name node-ip-app --rm node-ip-app:latest
# docker run -d -p 4503:4500 --name node-ip-app --rm tericcabrel/node-ip-app:latest
8 changes: 8 additions & 0 deletions node-ip-address/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ const PORT = parseInt(process.env.PORT || '4500');

const app = express();

app.set('trust proxy', true);

app.use(express.urlencoded({ extended: true }));
app.use(express.json());

app.get('/', (req, res) => {
return res.json({ message: 'Hello World!' });
});

app.get('/ipv4', (req, res) => {
const ipAddress = req.ip;

return res.json({ message: `Hello! Your IP address is: ${ipAddress}` });
});

app.listen(PORT, () => {
console.log(`Application started on URL ${HOST}:${PORT} 🎉`);
});

0 comments on commit fc7a299

Please sign in to comment.