Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
daa-custom-stack
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Felipe Vieira de Moraes Tavares
daa-custom-stack
Commits
a29aa126
Commit
a29aa126
authored
Feb 13, 2017
by
nemoNoboru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
people backed finished
parent
ca7f9f90
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
10 deletions
+51
-10
Dockerfile
backend/Dockerfile
+1
-1
db.js
backend/app/db/db.js
+9
-1
index.js
backend/app/index.js
+18
-6
people.js
backend/app/people/people.js
+22
-1
docker-compose.yml
backend/docker-compose.yml
+1
-1
No files found.
backend/Dockerfile
View file @
a29aa126
...
@@ -14,4 +14,4 @@ COPY app /app
...
@@ -14,4 +14,4 @@ COPY app /app
EXPOSE
8080
EXPOSE
8080
CMD
[ "n
pm", "start
" ]
CMD
[ "n
ode", "index.js
" ]
backend/app/db/db.js
View file @
a29aa126
var
mongoose
=
require
(
'mongoose'
)
var
mongoose
=
require
(
'mongoose'
)
mongoose
.
connect
(
"mongodb://mongo:27017"
)
var
MONGO_DB
;
var
DOCKER_DB
=
process
.
env
.
DB_1_PORT
;
if
(
DOCKER_DB
)
{
MONGO_DB
=
DOCKER_DB
.
replace
(
"tcp"
,
"mongodb"
)
+
"/dev_db"
;
}
else
{
MONGO_DB
=
process
.
env
.
MONGODB
;
}
mongoose
.
connect
(
MONGO_DB
)
var
db
=
mongoose
.
connection
;
var
db
=
mongoose
.
connection
;
db
.
on
(
'error'
,
console
.
error
.
bind
(
console
,
'connection error:'
));
db
.
on
(
'error'
,
console
.
error
.
bind
(
console
,
'connection error:'
));
...
...
backend/app/index.js
View file @
a29aa126
...
@@ -3,6 +3,9 @@ var express = require('express')
...
@@ -3,6 +3,9 @@ var express = require('express')
// bodyParser is a lib that parses POST & PUT data
// bodyParser is a lib that parses POST & PUT data
var
bodyParser
=
require
(
'body-parser'
)
var
bodyParser
=
require
(
'body-parser'
)
// add some entities
var
people
=
require
(
"./people/people.js"
)
var
app
=
express
()
var
app
=
express
()
var
port
=
process
.
env
.
PORT
||
8080
;
var
port
=
process
.
env
.
PORT
||
8080
;
...
@@ -12,19 +15,28 @@ app.use(bodyParser.json())
...
@@ -12,19 +15,28 @@ app.use(bodyParser.json())
var
people_path
=
'/people'
var
people_path
=
'/people'
app
.
get
(
people_path
,
function
(
req
,
res
)
{
app
.
get
(
people_path
,
function
(
req
,
res
)
{
res
.
send
(
'some people here'
)
people
.
model
.
find
(
function
(
err
,
people
)
{
res
.
send
(
people
)
})
})
})
app
.
post
(
people_path
,
function
(
req
,
res
)
{
app
.
post
(
people_path
,
function
(
req
,
res
)
{
res
.
send
(
'create a person here'
)
var
person_name
=
req
.
body
.
name
people
.
create
(
person_name
,
function
(
err
)
{
res
.
send
(
err
)
})
})
})
app
.
put
(
people_path
,
function
(
req
,
res
)
{
app
.
put
(
people_path
+
"/:person_id"
,
function
(
req
,
res
)
{
res
.
send
(
'modify a person'
)
people
.
modify
(
req
.
params
.
person_id
,
req
.
body
.
name
,
function
(
err
)
{
res
.
send
(
err
)
})
})
})
app
.
delete
(
people_path
,
function
(
req
,
res
)
{
app
.
delete
(
people_path
+
"/:person_id"
,
function
(
req
,
res
)
{
res
.
send
(
'delete a person'
)
people
.
remove
(
req
.
params
.
person_id
,
function
(
err
)
{
res
.
send
(
err
)
})
})
})
app
.
listen
(
port
)
app
.
listen
(
port
)
backend/app/people/people.js
View file @
a29aa126
var
db
=
require
(
'../db/db.js'
)
var
db
=
require
(
'../db/db.js'
)
var
mongoose
=
require
(
'mongoose'
)
var
mongoose
=
require
(
'mongoose'
)
var
people
=
{}
db
.
once
(
'open'
,
function
()
{
db
.
once
(
'open'
,
function
()
{
// do things when connection opens
people
.
model
=
mongoose
.
model
(
'People'
,{
name
:
String
})
people
.
create
=
function
(
personName
,
callback
)
{
var
newPeople
=
new
people
.
model
({
name
:
personName
})
newPeople
.
save
(
callback
)
}
people
.
modify
=
function
(
id
,
name
,
callback
)
{
people
.
model
.
findById
(
id
).
then
(
function
(
person
)
{
person
.
name
=
name
person
.
save
(
callback
)
})
}
people
.
remove
=
function
(
id
,
callback
)
{
people
.
model
.
findById
(
id
).
remove
(
callback
)
}
})
})
module
.
exports
=
people
backend/docker-compose.yml
View file @
a29aa126
...
@@ -6,7 +6,7 @@ db:
...
@@ -6,7 +6,7 @@ db:
web
:
web
:
build
:
.
build
:
.
volumes
:
volumes
:
-
app:/app
-
./
app:/app
ports
:
ports
:
-
"
8000:8080"
-
"
8000:8080"
links
:
links
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment