From 4ac29d32e04bca017badb2960ce903b8a1fe0fb7 Mon Sep 17 00:00:00 2001 From: alien Date: Fri, 14 Aug 2020 10:21:12 +0800 Subject: [PATCH] first commit --- .idea/vcs.xml | 1 + Dockerfile | 19 +++++++++++++++++++ Dockerfile.service | 1 + docker-compose.yml | 14 +++++++++++++- go.mod | 1 + go.sum | 2 ++ nbaservice/rest/rest.go | 4 +++- playfront | 1 + 8 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 160000 playfront diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..b44f97d 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..78c00a5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM node:8 + +COPY playfront /app +WORKDIR /app +#RUN npm install -g webpack typescript +#RUN npm install +RUN npx webpack + +#RUN webpack + + +FROM nginx:1.11-alpine + +COPY --from=0 /app/index.html /usr/share/nginx/html/ +COPY --from=0 /app/dist /usr/share/nginx/html/dist/ +COPY --from=0 /app/node_modules/bootstrap/dist/css/bootstrap.min.css /usr/share/nginx/html/node_modules/bootstrap/dist/css/bootstrap.min.css +COPY --from=0 /app/node_modules/react/umd/react.production.min.js /usr/share/nginx/html/node_modules/react/umd/react.production.min.js +COPY --from=0 /app/node_modules/react-dom/umd/react-dom.production.min.js /usr/share/nginx/html/node_modules/react-dom/umd/react-dom.production.min.js +COPY --from=0 /app/node_modules/whatwg-fetch/fetch.js /usr/share/nginx/html/node_modules/whatwg-fetch/fetch.js diff --git a/Dockerfile.service b/Dockerfile.service index ffb529e..9f30b26 100644 --- a/Dockerfile.service +++ b/Dockerfile.service @@ -10,6 +10,7 @@ ENV GOPATH=/go RUN go get "github.com/gorilla/mux" RUN go get "gopkg.in/mgo.v2" +RUN go get "github.com/gorilla/handlers" RUN CGO_ENABLED=0 GOOS=linux go build -o /nbaservice ./nbaservice diff --git a/docker-compose.yml b/docker-compose.yml index 31b3241..011c975 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,8 @@ version: "3" services: - test: + playerser: + container_name: "playerser" build: context: .. dockerfile: ./nbarest/Dockerfile.service @@ -11,6 +12,17 @@ services: - mongodb mongodb: + container_name: "mongodb" image: mongo ports: - "27017:27017" + + front: + container_name: "front" + build: + context: . + dockerfile: ./Dockerfile + ports: + - "80:80" + links: + - playerser \ No newline at end of file diff --git a/go.mod b/go.mod index d62a5f5..43cdda3 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module nbarest go 1.14 require ( + github.com/gorilla/handlers v1.4.2 github.com/gorilla/mux v1.7.4 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 ) diff --git a/go.sum b/go.sum index 9ff9e7e..435eb39 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg= +github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw= diff --git a/nbaservice/rest/rest.go b/nbaservice/rest/rest.go index be03ae5..b2cd088 100644 --- a/nbaservice/rest/rest.go +++ b/nbaservice/rest/rest.go @@ -2,6 +2,7 @@ package rest import ( "fmt" + "github.com/gorilla/handlers" "github.com/gorilla/mux" "nbarest/lib/persistence" "net/http" @@ -16,6 +17,7 @@ func ServeAPI(endpoint string,dbhandler persistence.DatabaseHandler) error{ playersrouter.Path("/").HandlerFunc(handler.FindAllPlayerHandler).Methods("GET") playersrouter.Path("/").HandlerFunc(handler.NewPlayerHandler).Methods("POST") fmt.Println("listen") - return http.ListenAndServe(endpoint,r) + server := handlers.CORS()(r) + return http.ListenAndServe(endpoint, server) } diff --git a/playfront b/playfront new file mode 160000 index 0000000..717abfa --- /dev/null +++ b/playfront @@ -0,0 +1 @@ +Subproject commit 717abfab12d35208d1d55dc4cb1395fb58dbc838