-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paths3-list.js
More file actions
64 lines (50 loc) · 1.37 KB
/
Copy paths3-list.js
File metadata and controls
64 lines (50 loc) · 1.37 KB
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
62
63
64
// Dependencias
var AWS = require('aws-sdk');
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
// 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){
// Iniciando objeto S3
var s3 = new AWS.S3();
s3.listBuckets(function(error, data) {
if (error) {
returnS3(error);
console.log(error);
} else {
returnS3(data);
console.log(data);
}
});
var returnS3 = function(result){
result = JSON.stringify(result);
var body = '<html>'
+' <head>'
+' <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"/>'
+' </head>'
+' <body>'
+ result
+' </body>'
+'</html>';
console.log(result);
res.writeHead(200,{"Content-Type" : "text/html"});
res.write(body);
res.end();
}
});
app.listen(8080,function(){
console.log("Conectado e escutando na porta 8080");
});