diff --git a/.gitignore b/.gitignore index b2d146bc88131086e8ca87d36df7f2841b2dcc23..1f9315789d75f09507c278985196223440623702 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .vscode .env -.DS_Store \ No newline at end of file +.DS_Store diff --git a/backend b/backend index 606de9abcc34c5624f48aa640b4bac28c8395d41..00ab0beaa55c3899bff793aa916ced3fc42a3fd8 160000 --- a/backend +++ b/backend @@ -1 +1 @@ -Subproject commit 606de9abcc34c5624f48aa640b4bac28c8395d41 +Subproject commit 00ab0beaa55c3899bff793aa916ced3fc42a3fd8 diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000000000000000000000000000000000000..f65cf0181d62cc0f8d4c794fe036bd80caaa34fb --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,64 @@ +version: '3' + +services: + proxy: + build: + context: ./proxy + container_name: cs_prod_proxy + ports: + - 80:80 + networks: + - app + depends_on: + - backend + - frontend + + backend: + build: + context: ./backend + target: production + container_name: cs_prod_backend + ports: + - 3000:80 + env_file: + - ./backend/.env + networks: + - app + depends_on: + - mysql + + frontend: + build: + context: ./frontend + target: production + container_name: cs_prod_frontend + ports: + - 3001:80 + env_file: + - ./backend/.env + networks: + - app + depends_on: + - backend + + mysql: + image: mysql:8.0 + container_name: cs_prod_mysql + volumes: + - mysql:/var/lib/mysql + ports: + - 3306:3306 + environment: + MYSQL_ROOT_PASSWORD: '12345' + MYSQL_ROOT_HOST: '%' + MYSQL_DATABASE: 'collab_space' + MYSQL_USER: 'user' + MYSQL_PASSWORD: '12345' + MYSQL_ALLOW_EMPTY_PASSWORD: 1 + networks: + - app + +networks: + app: +volumes: + mysql: diff --git a/docker-compose.yml b/docker-compose.yml index cbd18176c4c6aa860267dada5e468f099109d669..5987f8d1d74ae56a309047baa45ac406a7d31b20 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,7 @@ services: backend: build: context: ./backend + target: development container_name: cs_backend command: npm run start:dev volumes: @@ -21,6 +22,7 @@ services: frontend: build: context: ./frontend + target: development container_name: cs_frontend command: npm run dev -- --host volumes: diff --git a/frontend b/frontend index b5b6d351f0d3358e7ae7c89f528b4d63d0fc28af..4320ae7023bf375abb07a6d6caa17fa62e0638c3 160000 --- a/frontend +++ b/frontend @@ -1 +1 @@ -Subproject commit b5b6d351f0d3358e7ae7c89f528b4d63d0fc28af +Subproject commit 4320ae7023bf375abb07a6d6caa17fa62e0638c3 diff --git a/proxy/Dockerfile b/proxy/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..17cfc2b1beaf8819f939dc8d3a2239377b03656c --- /dev/null +++ b/proxy/Dockerfile @@ -0,0 +1,5 @@ +FROM nginx:alpine + +COPY ./default.conf /etc/nginx/conf.d/default.conf + +COPY ./includes/ /etc/nginx/includes/ \ No newline at end of file diff --git a/proxy/default.conf b/proxy/default.conf new file mode 100644 index 0000000000000000000000000000000000000000..8be6999a37e6ed5febb6c2fb4fa3bdc4dd40c4f3 --- /dev/null +++ b/proxy/default.conf @@ -0,0 +1,39 @@ + server { + listen 80; + server_name api.collabspace-app.com; + location / { + include /etc/nginx/includes/proxy.conf; + proxy_pass http://backend; + include /etc/nginx/includes/cors.conf; + } + } + + server { + listen 80; + server_name collabspace-app.com; + location / { + include /etc/nginx/includes/proxy.conf; + proxy_pass http://frontend; + error_page 404 = /index.html; + } + } + + server { + listen 80; + server_name api.collabspace.local; + location / { + include /etc/nginx/includes/proxy.conf; + proxy_pass http://backend; + include /etc/nginx/includes/cors.conf; + } + } + + server { + listen 80; + server_name collabspace.local; + location / { + include /etc/nginx/includes/proxy.conf; + proxy_pass http://frontend; + error_page 404 = /index.html; + } + } \ No newline at end of file diff --git a/proxy/includes/cors.conf b/proxy/includes/cors.conf new file mode 100644 index 0000000000000000000000000000000000000000..73a5013152ab2c72bb7f6a4ec58d52150aec4e95 --- /dev/null +++ b/proxy/includes/cors.conf @@ -0,0 +1,44 @@ +# if ($http_origin ~ '(collabspace\.local$)|(collabspace-app\.com$)') { +# add_header 'Access-Control-Allow-Origin' "*" always; +# add_header 'Access-Control-Allow-Credentials' 'true' always; +# add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; +# add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; +# add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; +# } +# +# if ($request_method = 'OPTIONS') { +# add_header 'Access-Control-Max-Age' 1728000; +# add_header 'Content-Type' 'text/plain; charset=utf-8'; +# add_header 'Content-Length' 0; +# return 204; +# } + +set $cors ''; + +if ($http_origin ~ '(collabspace\.local$)|(collabspace-app\.com$)') { + set $cors 'origin_matched'; +} + +if ($request_method = OPTIONS) { + set $cors '${cors} & preflight'; +} + +if ($cors = 'origin_matched') { + add_header 'Access-Control-Allow-Origin' '$http_origin' always; + add_header 'Access-Control-Allow-Credentials' 'true' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; +} + +if ($cors = 'origin_matched & preflight') { + add_header 'Access-Control-Allow-Origin' '$http_origin' always; + add_header 'Access-Control-Allow-Credentials' 'true' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain; charset=utf-8'; + add_header 'Content-Length' 0; + return 204; +} \ No newline at end of file diff --git a/proxy/includes/proxy.conf b/proxy/includes/proxy.conf new file mode 100644 index 0000000000000000000000000000000000000000..90c764d12790ac9c70c466b62345cf55590ecf1f --- /dev/null +++ b/proxy/includes/proxy.conf @@ -0,0 +1,5 @@ +access_log off; +proxy_intercept_errors on; +proxy_set_header X-Real-IP $remote_addr; +proxy_set_header Host $host; +proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \ No newline at end of file