3a-classic / score-api-server

This is a score api server
Apache License 2.0
1 stars 1 forks source link

score-api-server

Circle CI Coverage Status Stories in Ready Bitdeli Badge Join the chat at https://gitter.im/3a-classic/score-api-server Apache2.0 License

DESCRIPTION

This is api server for 3a-classic

DEPENDENCY

REQUIRED CONFIGURATION

USAGE

MONGO

you can use official docker images of mongo

$ docker run --name 3a-classic-mongo -d mongo

3A-CLASSIC-SERVER

$ cd /path/to/work/dir
$ git clone http://git.sadayuki-matsuno.com/3aclassic/3a-classic-server.git
$ gb build
$ docker run -d -t \
  -v $HOME/3a-classic/server/score-api-server:/go/src \
  --name score-api-server \
  --expose 80 \
  -p 8081:80 \
  -e "SLACK_INCOMING_HOOK_URL=https://hooks.slack.com/***********" \
  -e "SLACK_CHANNEL=#3a-classic" \
  -e "SLACK_USERNAME=3a-classic-error-log" \
  -e "MONGO_HOST=172.17.0.33" \
  -e "MONGO_PORT=27017" \
  -e "MONGO_DB=test" \
  -e "MONGO_LOG_COLLECTION=log" \
  -e "GIT_REMOTE_SERVICE=github" \
  -e "GIT_REMOTE_URL=https://github.com/3a-classic/score-api-server" \
  -e "AUTH_ADMIN_PASS_BASE=*********" \
  golang:latest \
  bash -c /go/src/bin/3aClassic-linux-amd64
http://localhost:8081

Environment Variables

Key ExampleValue Default Explain
SLACK_INCOMING_HOOK_URL https://hooks.slack.com/*** "" Notify you of error logs by Slack
SLACK_CHANNEL #3a-classic Depend on slackrus Slack use this channel
SLACK_USERNAME 3a-classic-error-log Depend on slackrus Slack use this username
MONGO_HOST 172.17.0.33 mongo MongoDB hostname or IP
MONGO_PORT 27017 27017 MongoDB port
MONGO_DB test test MongoDB database name
MONGO_LOG_COLLECTION log log MongoDB log collection name
GIT_REMOTE_SERVICE github/gitlab github for writing error code location in logs. you can also choose "gitlab"
GIT_REMOTE_URL https://github.com/3a-classic/score-api-server https://github.com/3a-classic/score-api-server for writing error code location in logs.

Variable Name is not same as Docker one, because I heard Docker Link is "Legacy" somewhere.

CORS

if you access by chrome, you have to set CORS. this is example to configure CORS in nginx.

$ vim /etc/nginx/conf.d/proxy.conf

add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

if ($request_method = 'OPTIONS') {
        return 204;
}

if you use nginx-proxy, add file below.

$ vim /etc/nginx/vhost.d/default_location 

  add_header 'Access-Control-Allow-Origin' '$http_origin';
  add_header 'Access-Control-Allow-Credentials' 'true';
  add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
  add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With';

if ($request_method = 'OPTIONS') {
        return 204;
}

if ($request_method = 'POST') {
  add_header Access-Control-Allow-Origin '';
}

WEBSOCKET

if you use webdocket, you have to set below in nginx.

$ vim /etc/nginx/conf.d/proxy.conf

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;

CAUTION

FOR DEVELOPER

if you edit and run this code, ready for development.

GB

I use gb as golang package manager

$ go get github.com/constabulary/gb/...
$ cd 3a-classic-server
$ gb vendor restore ./vendor/manifest
$ gb build

now you can run code compiled.

$ ./bin/3aClassic

AUTHOR

Sadayuki Matsuno