Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clubpetro challange backend #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

node_modules/
44 changes: 44 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const express = require('express');
const app = express();
const morgan = require('morgan');
const bodyParser = require('body-parser');

const rotaLugares = require('./routes/lugares');

app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.use((req, res, next)=>{
res.header('Acces-Control-Allow-Orign', '*'),
res.header(
'Acces-Control-Allow-Header',
'Origin, X-Requested-With, Content-Type, Accept, Authorization'
);
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH, DELETE, GET');
return res.status(200).send({});
}

next();
});

app.use('/lugares', rotaLugares);

app.use((req,res,next)=>{
const erro = new Error('Não encontrado');
erro.status = 404;
next(erro);
});

app.use((error, req, res, next)=>{
res.status(error.status || 500);
return res.send({
erro: {
mensagem: error.message
}
})
})


module.exports = app;
Binary file added db/modelagem.mwb
Binary file not shown.
Binary file added db/modelagem.mwb.bak
Binary file not shown.
11 changes: 11 additions & 0 deletions mysql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var mysql = require('mysql2');

var pool = mysql.createPool({
"user" : process.env.MYSQL_USER,
"password" : process.env.MYSQL_PASSWORD,
"database" : process.env.MYSQL_DATABASE,
"host": process.env.MYSQL_HOST,
"port" : process.env.MYSQL_PORT
});

exports.pool = pool;
9 changes: 9 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"env" : {
"MYSQL_USER" : "root",
"MYSQL_PASSWORD" : "0000",
"MYSQL_DATABASE" : "desafio",
"MYSQL_HOST" : "localhost",
"MYSQL_PORT" : "3306"
}
}
Loading