Skip to content
Merged
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
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:current-slim
FROM arm64v8/node:18.14-buster-slim

RUN apt-get update -y && apt-get upgrade -y
RUN apt-get update && apt-get upgrade -y


WORKDIR /SIMPLE-NODE-API
Expand All @@ -11,6 +11,8 @@ RUN npm install
COPY ./routes.js routes.js
COPY ./server.js server.js
COPY ./todos.js todos.js
COPY ./cron.js cron.js


EXPOSE 1337
ENTRYPOINT [ "node", "server" ]
23 changes: 23 additions & 0 deletions cron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var CronJob = require('cron').CronJob;
const { default: axios } = require('axios');
var express = require('express');
const http = require(`http`);
const app = express();
app.get(`/health`, (req, res) => res.status(200).json(`OK`));
const server = http.createServer(app);
server.listen(
1337,
() => console.log(`-- Backend Service (1337) --`)
);

const job = new CronJob('0 */1 * * * *', async function () {
try {
let response = await axios.get(process.env.CLIENT_URL)//configurar o CLIENT_URL=https://something/health
console.log('Resposta so servidor: OK', JSON.stringify(response.data))
} catch (error) {
console.log('ocorreu um erro:', JSON.stringify(error))
}

});
console.log('Resposta do servidor a cada minuto');
job.start();
89 changes: 89 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.3.4",
"cron": "^2.3.0",
"express": "^4.16.4"
}
}