This is api server for 3a-classic
you can use official docker images of mongo
$ docker run --name 3a-classic-mongo -d mongo
$ 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
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.
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 '';
}
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;
if you edit and run this code, ready for development.
I use gb as golang package manager
$ go get github.com/constabulary/gb/...
install bzr
change directry to this repo
$ cd 3a-classic-server
$ gb vendor restore ./vendor/manifest
$ gb build
now you can run code compiled.
$ ./bin/3aClassic
Sadayuki Matsuno