diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9befaf7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,64 @@ +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/dictionaries +.idea/**/shelf + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ +cmake-build-release/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests +### VisualStudioCode template +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### Remove MongoDB Docker Data from Git +MongoDB/** + diff --git a/Nginx/conf.d/app.conf b/Nginx/conf.d/app.conf new file mode 100644 index 0000000..39da689 --- /dev/null +++ b/Nginx/conf.d/app.conf @@ -0,0 +1,13 @@ +server { + listen 80; + charset utf-8; + access_log off; + + location / { + proxy_pass http://frontend:8080; + proxy_set_header Host $host:$server_port; + proxy_set_header X-Forwarded-Host $server_name; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} \ No newline at end of file diff --git a/README.md b/README.md index 0b06c8f..e8f47ff 100644 --- a/README.md +++ b/README.md @@ -94,8 +94,9 @@ FocusBlock uses a Node.js server in order to handle communication between the cl Start by creating a `.env` file that will store these properties: -- `BASE_PATH`=localhost:3000 -- `DB_PATH`=mongodb://localhost:27017/focusblock +- `BASE_PATH`=localhost +- `PORT`=3000 +- `DB_HOST`=localhost:27017 - `DB_NAME`=focusblock ##### Start Server diff --git a/Server/.dockerignore b/Server/.dockerignore new file mode 100644 index 0000000..ecd52c6 --- /dev/null +++ b/Server/.dockerignore @@ -0,0 +1,5 @@ +.git +.gitignore +README.md +docker-compose.yml +node_modules \ No newline at end of file diff --git a/Server/Database/db.js b/Server/Database/db.js index 78019be..1c3d509 100644 --- a/Server/Database/db.js +++ b/Server/Database/db.js @@ -4,7 +4,7 @@ var db; // Connect to DB // MongoClient.connect( - process.env.DB_PATH, + `mongodb://${process.env.DB_HOST}/${process.env.DB_NAME}`, { useNewUrlParser: true }, (error, client) => { if (error) throw error; diff --git a/Server/Dockerfile b/Server/Dockerfile new file mode 100644 index 0000000..5122c7d --- /dev/null +++ b/Server/Dockerfile @@ -0,0 +1,16 @@ +FROM node:8-slim + +RUN mkdir /app + +RUN npm install nodemon -g + +WORKDIR /app +COPY . . +#ADD . . + +RUN npm install + + +EXPOSE 3000 + +CMD npm start \ No newline at end of file diff --git a/Server/nodemon.json b/Server/nodemon.json new file mode 100644 index 0000000..f1b04c6 --- /dev/null +++ b/Server/nodemon.json @@ -0,0 +1,6 @@ +{ + "env": { + "NODE_ENV": "development" + }, + "ext": "js json hjs" +} \ No newline at end of file diff --git a/Server/server.js b/Server/server.js index a80abb4..d4b97ad 100644 --- a/Server/server.js +++ b/Server/server.js @@ -21,7 +21,7 @@ server.post('/new', async (req, res) => { let id = shortid.generate(); let userObj = { _id: id, - url: `${process.env.BASE_PATH}/dashboard/${id}`, + url: `${process.env.BASE_PATH}:${process.env.PORT}/dashboard/${id}`, focusBlocks: [] }; diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..7c316f6 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,61 @@ +version: '3' +services: + nginx: + container_name: focusblock-nginx + image: nginx:latest + #restart: always + ports: + - "80:80" + volumes: + - ./Nginx/conf.d:/etc/nginx/conf.d + links: + - frontend + depends_on: + - frontend + + mongodb: + container_name: focusblock-mongodb + image: mongo:latest + command: mongod --storageEngine=wiredTiger + ports: + - "27017:27017" + volumes: + - ./MongoDB:/data/db + + backend: + container_name: focusblock-backend + build: ./Server + restart: on-failure + environment: + BASE_PATH: localhostxs + DB_HOST: mongodb:27017 + DB_NAME: focusblock + PORT: 3000 + #volumes: + # - ./Server:/app + ports: + - "3000:3000" + links: + - mongodb + depends_on: + - mongodb + + frontend: + container_name: focusblock-frontend + build: "./focus-block" + environment: + #SMTP Username for SMTPJS (From Sengrid) + REACT_APP_SMTP_USERNAME: CHANGE_ME + #SMTP Password for SMTPJS (From Sengrid) + REACT_APP_SMTP_PW: CHANGE_ME_TOO + #The route for your Node Server (ex. http://localhost:8000) + REACT_APP_API_BASE: http://backend:3000 + PORT: 8080 + #volumes: + # - ./focus-block:/app + ports: + - "8080:8080" + links: + - backend + depends_on: + - backend diff --git a/focus-block/.dockerignore b/focus-block/.dockerignore new file mode 100644 index 0000000..ee2bbf0 --- /dev/null +++ b/focus-block/.dockerignore @@ -0,0 +1,5 @@ +.git +../Server/.gitignore +README.md +docker-compose.yml +node_modules \ No newline at end of file diff --git a/focus-block/Dockerfile b/focus-block/Dockerfile new file mode 100644 index 0000000..61583ea --- /dev/null +++ b/focus-block/Dockerfile @@ -0,0 +1,13 @@ +FROM node:8-slim + +RUN mkdir /app +RUN npm install npm-run-all -g + +WORKDIR /app +COPY . . +#ADD . . +RUN npm install + +EXPOSE 8080 + +CMD npm start \ No newline at end of file