Skip to content

Commit afd4b26

Browse files
committed
Integrando Docker
1 parent 35873f3 commit afd4b26

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
npm-debug.log

Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM node:boron
2+
3+
MAINTAINER Raphael Lima <raphael.aolima8@gmail.com>
4+
5+
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
6+
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
7+
RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
8+
USER postgres
9+
RUN /etc/init.d/postgresql start &&\
10+
createdb api -O postgres
11+
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
12+
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
13+
EXPOSE 5432
14+
VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
15+
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
16+
17+
USER root
18+
RUN mkdir -p /usr/src/ts-api
19+
WORKDIR /usr/src/ts-api
20+
21+
COPY package.json /usr/src/ts-api
22+
RUN npm install
23+
24+
COPY . /usr/src/ts-api
25+
EXPOSE 4000
26+
27+
CMD npm run watch

server/config/config.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"development": {
3+
"username": "postgres",
4+
"password": "pgroot",
5+
"database": "api",
6+
"host": "127.0.0.1",
7+
"dialect": "postgres",
8+
"secret": "typescriptAPI",
9+
"jwtSession": { "session": false }
10+
},
11+
"test": {
12+
"username": "root",
13+
"password": null,
14+
"database": "database_test",
15+
"host": "127.0.0.1",
16+
"dialect": "mysql"
17+
},
18+
"production": {
19+
"username": "root",
20+
"password": null,
21+
"database": "database_production",
22+
"host": "127.0.0.1",
23+
"dialect": "mysql"
24+
}
25+
}

server/models/user.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as bcrypt from 'bcrypt';
2+
export default function(sequelize, DataTypes) {
3+
var User = sequelize.define('User', {
4+
id: {
5+
type: DataTypes.STRING,
6+
primaryKey: true,
7+
autoIncrement: true
8+
},
9+
name: {
10+
type: DataTypes.STRING,
11+
allowNull: false,
12+
validate: {
13+
notEmpty: true
14+
}
15+
},
16+
email: {
17+
type: DataTypes.STRING,
18+
allowNull: false,
19+
validate: {
20+
notEmpty: true,
21+
}
22+
},
23+
password: {
24+
type: DataTypes.STRING,
25+
allowNull: false,
26+
validate: {
27+
notEmpty: true,
28+
}
29+
}
30+
}, {
31+
classMethods: {
32+
validatePassword: (encryptedPassword, password) => bcrypt.compareSync(password, encryptedPassword)
33+
}
34+
});
35+
36+
User.beforeCreate((user) => {
37+
return hashPass(user);
38+
})
39+
40+
function hashPass(user) {
41+
const salt = bcrypt.genSaltSync(10);
42+
user.set('password', bcrypt.hashSync(user.password, salt));
43+
}
44+
return User;
45+
};

0 commit comments

Comments
 (0)