crew-backend-challenge
Simple RestFULL API microservice (deployed here)
Installation
- Install the latest version of docker-ce. ( Ubuntu | Debian )
- Install the latest version of docker-compose
- Run
docker-compose up -d
- Add to your environment
MONGO_URI=mongodb://root:passwd@127.0.0.1:27017
- Install dependencies with
go get -v -t -d .
- Run app
go run main.go
or build&run with go build . && ./crew-backend-challenge
Deploy
- Install Go, mongoDb, nginx
- Create a service using systemctl :
[Unit]
Description=Crew backend challenge API
[Service]
Type=simple
Restart=always
RestartSec=5s
WorkingDirectory=/home/john/go/src/github.com/DrSmithFr/crew-backend-challenge
Environment="MONGO_URI=mongodb://user:passwd@127.0.0.1:27017"
ExecStart=/home/john/go/src/github.com/DrSmithFr/crew-backend-challenge/crew-backend-challenge
[Install]
WantedBy=multi-user.target
- Add to add proxy_pass to a nginx site configuration :
location /v1/ {
# Simple requests
add_header "Access-Control-Allow-Origin" *;
# Preflighted requests
if ($request_method = OPTIONS ) {
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
return 200;
}
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://localhost:8080/;
}
Bonus
Watch more of my code on github.com/DrSmithFr/go-console 😇