forked from KubeDev/api-conversao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (30 loc) · 1.14 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
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');
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.listen(8080, () => {
console.log("Servidor rodando na porta 8080");
});