Skip to content

Commit

Permalink
Connect to the database postgres and store requests inside the database
Browse files Browse the repository at this point in the history
[refs #f34238344b71]
  • Loading branch information
jfahrer committed May 5, 2018
1 parent 791c6a3 commit 8b67cda
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion developing/webapp/app.rb
@@ -1,8 +1,14 @@
require 'sinatra'
require 'pg'

set :bind, '0.0.0.0'
set :port, 9494

get '/' do
'Hello world!'
conn = PG::Connection.open(ENV['POSTGRES_HOST'], 5432, '', '', ENV['POSTGRES_DB'],
ENV['POSTGRES_USER'], ENV['POSTGRES_PASSWORD'])
sql = "INSERT INTO requests (ip, path, host, requested_at) VALUES ($1, $2, $3, $4)"
res = conn.exec(sql, [request.ip, '/', Socket.gethostname, Time.now])
conn.finish
'Hello, World!'
end
5 changes: 5 additions & 0 deletions developing/webapp/docker-compose.yml
Expand Up @@ -5,6 +5,11 @@ services:
image: jfahrer/webapp-ruby:latest
build:
context: .
environment:
- POSTGRES_USER=demo
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=demo
- POSTGRES_HOST=pg
volumes:
- .:/app
ports:
Expand Down

0 comments on commit 8b67cda

Please sign in to comment.