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

Emerson test exercise back #2

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
on: [push, pull_request]

jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: stefanoeb/eslint-action@1.0.2
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:alpine

WORKDIR /app

COPY package.json .

RUN npm install

COPY . .

CMD ["node", "src/api/server"]
5 changes: 5 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build:
docker:
web: Dockerfile
run:
web: node src/api/server.js
2,777 changes: 1,242 additions & 1,535 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"express-rescue": "^1.1.31",
"pg": "^8.7.1",
"pg-hstore": "^2.3.4",
"sequelize": "^6.7.0"
"sequelize": "^6.7.0",
"eslint-config-trybe-backend": "^1.0.4"
},
"devDependencies": {
"eslint-config-trybe-backend": "^1.0.4",
"jest": "^27.3.1",
"nodemon": "^2.0.14",
"supertest": "^6.1.6"
Expand Down
3 changes: 3 additions & 0 deletions src/api/app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const express = require('express');
const rescue = require('express-rescue');
const cors = require('cors');
const UserController = require('../controllers/user');
const errorMiddleware = require('../middlewares/error');

const app = express();

app.use(cors());

app.get('/users', rescue(UserController));

app.use(errorMiddleware);
Expand Down
3 changes: 2 additions & 1 deletion src/api/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const app = require('./app');
require('dotenv/config');

const PORT = 3000;
const PORT = process.env.PORT || 3000;

app.listen(PORT, () => console.log(`Rodando na porta ${PORT}`));
33 changes: 20 additions & 13 deletions src/sequelize/config/config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
require('dotenv/config');

const { HOST, PASSWORD_POSTGRES, DATABASE, DB_USERNAME, DB_PORT } = process.env;

module.exports = {
development: {
username: 'root',
password: null,
database: 'database_development',
host: '127.0.0.1',
username: DB_USERNAME,
password: PASSWORD_POSTGRES,
database: DATABASE,
host: HOST,
port: DB_PORT,
dialect: 'postgres',
},
test: {
username: 'root',
password: null,
database: 'database_test',
host: '127.0.0.1',
username: DB_USERNAME,
password: PASSWORD_POSTGRES,
database: DATABASE,
host: HOST,
port: DB_PORT,
dialect: 'postgres',
},
production: {
username: 'root',
password: null,
database: 'database_test',
host: '127.0.0.1',
username: DB_USERNAME,
password: PASSWORD_POSTGRES,
database: DATABASE,
host: HOST,
port: DB_PORT,
dialect: 'postgres',
},
};
};