forked from jonathanbaraldi/api-treinamento-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
61 lines (51 loc) · 1.49 KB
/
server.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
55
56
57
58
59
60
61
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
// Configurações
var port = 8080;
// Parsear o conteudo
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
// Configuração da requisição, cabeçalhos, etc. CORS
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
// Métodos que queremos permitir
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
// GET
app.get('/',function(req,res){
var data = {
"Data":"",
"Ver" : "1.0",
};
data["Data"] = "API de Serviços do Jon - retorno em JSON";
res.json(data);
console.log(data);
});
// GET
app.get('/html',function(req,res){
var body = '<html>'
+' <head>'
+' <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"/>'
+' </head>'
+' <body>'
+' <h1>API de Serviços do Jon - retorno em HTML</h1>'
+' <form action="/upload" method="post">'
+' <textarea name="text" rows="20" cols="60"></textarea>'
+' <input type="submit" value="Submit text"/>'
+' </form>'
+' </body>'
+' </html>';
console.log(body);
res.writeHead(200,{"Content-Type" : "text/html"});
res.write(body);
res.end();
});
// ===================================
app.listen(port,function(){
console.log("Conectado e escutando na porta :8080");
});