rodrigobranas / youtube

Código das séries do Youtube
921 stars 558 forks source link

Backend externo #17

Open LoscaraDK opened 8 years ago

LoscaraDK commented 8 years ago

estou tentando carregar um objeto no meu json externo mas não está funcionando, alguém poderia me ajudar.

expressjs

LoscaraDK commented 8 years ago

var express = require('express'), app = express(), //log requests to the console (express4) morgan = require('morgan'),
// pull information from HTML POST (express4) bodyParser = require('body-parser'),
// simulate DELETE and PUT (express4) methodOverride = require('method-override'), http = require('http');

// set .html as the default extension app.set('view engine', 'html'); app.set('views',__dirname + '/views');

// Block the header from containing information // about the server app.disable('x-powered-by');

// Defines the port to run on app.set('port', process.env.PORT || 3000);

//Carrega tudo que esta dentro da pasta public //ex: http://localhost:3000/static/img/image001.png //ex: http://localhost:3000/img/image001.png //app.use('/static', express.static(dirname + '/public')); //app.use(express.static('public')); app.use('/manutencao-eventos', express.static(dirname + '/public')); app.use('/manutencao-eventos/node_modules', express.static(__dirname + '/node_modules')); // log every request to the console app.use(morgan('dev'));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/json
app.use(bodyParser.json());
// parse application/vnd.api+json as json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); app.use(methodOverride());

app.all('', function(req, res, next) { res.header('Access-Control-Allow-Origin', ''); res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS'); res.header('Access-Control-Allow-Headers', 'Content-Type'); next(); });

// Define some routes. app.get receives a path and a // function and it defines our routes. The path isn't // case sensitive and doesn't care about trailing path // information. // The req object represents the HTTP request and // contains the query string, parameters, body, header // The res object is the response Express sends // when it receives a request app.get('/manutencao-eventos', function(req, res){ res.sendFile(__dirname + '/index.html'); //res.render('index'); });

app.get('/manutencao-eventos/views/footer.html', function(req, res){ res.sendFile(__dirname + '/views/footer.html'); });

app.get('/manutencao-eventos/eventos', function(req, res) { res.sendFile(__dirname + '/backend/eventos.json'); });

app.post('/manutencao-eventos/eventos', function(req, res) { // var aaa = res.sendFile(__dirname + '/backend/eventos.json'); // console.log(aaa); console.log(req.body); res.send(req.body);

});

app.get('/manutencao-eventos/tiposDeEvento', function(req, res) { res.sendFile(__dirname + '/backend/tiposDeEvento.json'); //res.json(operadoras); });

app.listen(app.get('port'), function(){ console.log('Express started on http://localhost:' + app.get('port') + '; press Ctrl-C to terminate'); });

LoscaraDK commented 8 years ago
Manutenção de Eventos

{{app}}

Preencha o campo data original
Campo data deve ter o formato dd/mm/yyyy
Campo data deve ter o formato brasileiro de dd/mm/yyyy - regex validation
```
Selecione o Tipo de Evento
Preencha o campo indicando se incorpora juros
Data Original Tipo Evento Incorpora Juros? Excluir?
{{evento.date | date: 'dd/MM/yyyy'}} {{evento.type.eventType | uppercase}} {{evento.isIncorporaJuros}}

 
```
LoscaraDK commented 8 years ago

eventos.json [ {"date": "new Date(2016,9,11)" , "type": {"eventType": "Pagamento de Juros", "id": 1, "isFinal": "NÃO"}, "isIncorporaJuros": false, "isRemove": false }, {"date": "new Date(2012,9,11)" , "type": {"eventType": "Vencimento (Resgate)", "id": 2, "isFinal": "SIM"}, "isIncorporaJuros": true, "isRemove": false }, {"date": "new Date(2011,9,11)" , "type": {"eventType": "Pagamento de Amortização", "id": 3, "isFinal": "NÃO"}, "isIncorporaJuros": false, "isRemove": false } ]

LoscaraDK commented 8 years ago

tiposDeEvento.json [ {"eventType" : "Pagamento de Juros" , "id": 1, "isFinal": "NÃO" }, {"eventType" : "Vencimento (Resgate)" , "id": 2, "isFinal": "SIM" }, {"eventType" : "Pagamento de Amortização", "id": 3, "isFinal": "NÃO" } ]