From 088fc6f8b8283a87b1ebaec3beb90800af2f4ea5 Mon Sep 17 00:00:00 2001 From: jarrodback Date: Thu, 10 Feb 2022 10:40:27 +0000 Subject: [PATCH 1/8] Add heroku --- .github/workflows/docker-publish.yml | 10 +--------- .github/workflows/{node.js.yml => pipeline.yml} | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) rename .github/workflows/{node.js.yml => pipeline.yml} (90%) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index b66f4bf..754de2e 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -39,15 +39,7 @@ jobs: - name: Build and push Docker images - Server uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: - context: ./server/ - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - - name: Build and push Docker images - Ui - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - with: - context: ./ui/ + context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/node.js.yml b/.github/workflows/pipeline.yml similarity index 90% rename from .github/workflows/node.js.yml rename to .github/workflows/pipeline.yml index 3cb6b81..8a14f38 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/pipeline.yml @@ -191,3 +191,19 @@ jobs: with: branch: gh-pages folder: dist + + deploy2heroku: + runs-on: ubuntu-latest + needs: [test-server,test-ui-unit,test-ui-integration] + + if: >- + github.event_name == 'pull_request' + steps: + - uses: actions/checkout@v2 + + - name: Deploy to Heroku + uses: AkhileshNS/heroku-deploy@v3.12.12 + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: "cssd-highway" + heroku_email: "b8043407@my.shu.ac.uk" \ No newline at end of file From 80207ec8c2fd761f603beb3aa02e1f2b5929e1a4 Mon Sep 17 00:00:00 2001 From: jarrodback Date: Thu, 10 Feb 2022 11:09:47 +0000 Subject: [PATCH 2/8] HT-31 Fix indentation --- .github/workflows/pipeline.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 8a14f38..222a55f 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -203,7 +203,7 @@ jobs: - name: Deploy to Heroku uses: AkhileshNS/heroku-deploy@v3.12.12 - with: - heroku_api_key: ${{secrets.HEROKU_API_KEY}} - heroku_app_name: "cssd-highway" - heroku_email: "b8043407@my.shu.ac.uk" \ No newline at end of file + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: "cssd-highway" + heroku_email: "b8043407@my.shu.ac.uk" \ No newline at end of file From ed2ceab41569d8363068f76a5d0bf288953b7952 Mon Sep 17 00:00:00 2001 From: jarrodback Date: Thu, 10 Feb 2022 17:19:58 +0000 Subject: [PATCH 3/8] HT-31 change production variable for mongo url --- server/config/db.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/config/db.config.js b/server/config/db.config.js index 20128fb..8052b39 100644 --- a/server/config/db.config.js +++ b/server/config/db.config.js @@ -6,6 +6,6 @@ module.exports = { url: "mongodb://localhost:27017/highwaytrackerdb_testing", }, production: { - url: "mongodb://mongo:27017/highwaytrackerdb", + url: process.env.MONGODB_URI, }, }; From ac296a5e9d37d0968546f6332ff4f6abc1d33cc7 Mon Sep 17 00:00:00 2001 From: jarrodback Date: Thu, 10 Feb 2022 17:48:39 +0000 Subject: [PATCH 4/8] HT-31 update UI prod server url --- ui/src/api/api.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/ui/src/api/api.js b/ui/src/api/api.js index abcaf2f..0a57bc7 100644 --- a/ui/src/api/api.js +++ b/ui/src/api/api.js @@ -2,8 +2,14 @@ const api = class Api { constructor() { - this.baseUrl = "http://localhost:3000"; - this.authUrl = "http://localhost:3000/auth"; + this.baseUrl = + process.env.NODE_ENV === "production" + ? "http://cssd-highway.herokuapp.com/" + : "http://localhost:3000"; + this.authUrl = + process.env.NODE_ENV === "production" + ? "http://cssd-highway.herokuapp.com/auth" + : "http://localhost:3000/auth"; } async getAllBills(queryString) { @@ -29,15 +35,15 @@ const api = class Api { async getBillById(billId) { return axios - .get(`${this.baseUrl}/bill/${billId}`, { - withCredentials: true, - }) - .then((response) => { - return response.data; - }) - .catch((error) => { - throw error; - }); + .get(`${this.baseUrl}/bill/${billId}`, { + withCredentials: true, + }) + .then((response) => { + return response.data; + }) + .catch((error) => { + throw error; + }); } async payBill(billId) { From 256ee8c88c2d76b3e963f2c3c7483995eda71960 Mon Sep 17 00:00:00 2001 From: jarrodback Date: Thu, 10 Feb 2022 18:00:31 +0000 Subject: [PATCH 5/8] HT-31 All https --- ui/src/api/api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/api/api.js b/ui/src/api/api.js index 0a57bc7..2b2c5c1 100644 --- a/ui/src/api/api.js +++ b/ui/src/api/api.js @@ -4,11 +4,11 @@ const api = class Api { constructor() { this.baseUrl = process.env.NODE_ENV === "production" - ? "http://cssd-highway.herokuapp.com/" + ? "https://cssd-highway.herokuapp.com/" : "http://localhost:3000"; this.authUrl = process.env.NODE_ENV === "production" - ? "http://cssd-highway.herokuapp.com/auth" + ? "https://cssd-highway.herokuapp.com/auth" : "http://localhost:3000/auth"; } From 5b85c09ee3fe3aa3cbe259543b0282c9a9b6e372 Mon Sep 17 00:00:00 2001 From: jarrodback Date: Thu, 10 Feb 2022 18:11:44 +0000 Subject: [PATCH 6/8] HT-31 add multiple origins --- server/app.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/server/app.js b/server/app.js index dabe168..2ddc209 100644 --- a/server/app.js +++ b/server/app.js @@ -4,8 +4,8 @@ const bodyParser = require("body-parser"); const cors = require("cors"); const cookieSession = require("cookie-session"); const cookieParser = require("cookie-parser"); -const swaggerUi = require('swagger-ui-express'), - swaggerDocument = require('./swagger.json') +const swaggerUi = require("swagger-ui-express"), + swaggerDocument = require("./swagger.json"); require("./database"); require("dotenv").config(); @@ -21,15 +21,20 @@ app.use( }) ); -app.use(cors({ origin: "http://localhost:8080", credentials: true })); +app.use( + cors({ + origin: ["http://localhost:8080", "https://jarrodback.github.io/"], + credentials: true, + }) +); /** * Router setup */ const authRouter = require("./routes/auth.routes"); const billRouter = require("./routes/bill.routes"); -app.get('/api-docs/swagger.json', (req, res) => res.json(swaggerDocument)); -app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)) +app.get("/api-docs/swagger.json", (req, res) => res.json(swaggerDocument)); +app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument)); /** * View Engine setup @@ -45,6 +50,6 @@ app.use(cookieParser()); // Configuring the main routes app.use("/auth", authRouter); -app.use("/bill", billRouter) +app.use("/bill", billRouter); module.exports = app; From 34d12408baab8a5a8c035f7a25e555b3981b6b45 Mon Sep 17 00:00:00 2001 From: jarrodback Date: Thu, 10 Feb 2022 18:37:57 +0000 Subject: [PATCH 7/8] HT-31 update origin #2 --- server/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/app.js b/server/app.js index 2ddc209..f82f2f0 100644 --- a/server/app.js +++ b/server/app.js @@ -23,7 +23,7 @@ app.use( app.use( cors({ - origin: ["http://localhost:8080", "https://jarrodback.github.io/"], + origin: ["http://localhost:8080", "https://jarrodback.github.io"], credentials: true, }) ); From 0f0babb57b46d9d66f910ada7ce269ed40beed93 Mon Sep 17 00:00:00 2001 From: jarrodback Date: Thu, 10 Feb 2022 18:53:41 +0000 Subject: [PATCH 8/8] HT-31 remove / --- ui/src/api/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/api/api.js b/ui/src/api/api.js index ee81b08..0280513 100644 --- a/ui/src/api/api.js +++ b/ui/src/api/api.js @@ -4,7 +4,7 @@ const api = class Api { constructor() { this.baseUrl = process.env.NODE_ENV === "production" - ? "https://cssd-highway.herokuapp.com/" + ? "https://cssd-highway.herokuapp.com" : "http://localhost:3000"; this.authUrl = process.env.NODE_ENV === "production"