-
Notifications
You must be signed in to change notification settings - Fork 664
/
index.js
54 lines (42 loc) · 1.66 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const express = require('express');
const os = require('os')
const app = express();
const swaggerUi = require('swagger-ui-express');
const YAML = require('yamljs');
const swaggerDocument = YAML.load('./swagger.yaml');
const config = require('./config/system-life');
const NodeHog = require('nodehog');
app.use(config.middlewares.healthMid);
app.use('/', config.routers);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.get('/fahrenheit/:valor/celsius', (req, res) => {
let valor = req.params.valor;
let celsius = (valor - 32) * 5 / 9;
res.json({ "celsius": celsius, "maquina": os.hostname() });
});
app.get('/celsius/:valor/fahrenheit', (req, res) => {
let valor = req.params.valor;
let fahrenheit = (valor * 9 / 5) + 32;
res.json({ "fahrenheit": fahrenheit, "maquina": os.hostname() });
});
app.get('/temperatura/fahrenheitparacelsius/:valor', (req, res) => {
let valor = req.params.valor;
let celsius = (valor - 32) * 5 / 9;
res.json({ "celsius": celsius });
});
app.get('/temperatura/celsiusparafahrenheit/:valor', (req, res) => {
let valor = req.params.valor;
let fahrenheit = (valor * 9 / 5) + 32;
res.json({ "fahrenheit": fahrenheit });
});
app.put('/stress/:elemento/tempostress/:tempoStress/intervalo/:intervalo/ciclos/:ciclos', (req, res) => {
const elemento = req.params.elemento;
const tempoStress = req.params.tempoStress * 1000;
const tempoFolga = req.params.tempoFolga * 1000;
const ciclos = req.params.ciclos;
new NodeHog(elemento, tempoStress, tempoFolga, ciclos).start();
res.send("OK");
});
app.listen(8080, () => {
console.log("Servidor rodando na porta 8080");
});