From f4907d0672b808b4d16cb145c6fd201ffbab6095 Mon Sep 17 00:00:00 2001 From: Devesh Shukla Date: Fri, 16 Aug 2024 20:35:18 +0530 Subject: [PATCH 1/3] deploying --- .github/workflows/deploy.yml | 4 ++-- backend/Dockerfile | 2 +- backend/package.json | 3 ++- backend/src/server.js | 24 ++++++++++++------------ frontend/.gitignore | 2 ++ frontend/src/utils/localhost.js | 2 +- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5615c45..0bd5cd9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -33,7 +33,7 @@ jobs: run: docker pull imdeveshshukla/quiet-backend # - name: Deploy to EC2 - # uses: appleboy/ssh-action@master + # uses: appleboy/ssh-action@master working # with: # host: ${{ secrets.SSH_HOST }} # username: ${{ secrets.SSH_USERNAME }} @@ -42,4 +42,4 @@ jobs: # sudo docker pull imdeveshshukla/quiet-backend:latest # sudo docker stop web-app || true # sudo docker rm web-app || true - # sudo docker run -e DATABASE_URL ${{ secrets.DB_URL }} --restart-always -d --name web-app -p 3005:3000 imdeveshshukla/quiet-backend:latest \ No newline at end of file + # sudo docker run --env-file .env --restart-always -d --name web-app -p 3000:3000 imdeveshshukla/quiet-backend:latest \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile index 0398549..c36447b 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -17,4 +17,4 @@ RUN npx prisma generate EXPOSE 3000 -CMD ["npm", "run", "dev"] +CMD ["npm", "run", "deploy"] diff --git a/backend/package.json b/backend/package.json index 57c000b..deac2fa 100644 --- a/backend/package.json +++ b/backend/package.json @@ -6,7 +6,8 @@ "type": "module", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "dev": "node src/server.js" + "dev": "nodemon src/server.js", + "deploy":"node src/server.js" }, "author": "", "license": "ISC", diff --git a/backend/src/server.js b/backend/src/server.js index 405e225..e20b951 100644 --- a/backend/src/server.js +++ b/backend/src/server.js @@ -15,19 +15,19 @@ dotenv.config({ }) const app = express() const port = 3000 -const whitelist = ['http://localhost:5173', 'http://localhost:3000'] const corsOptions = { - credentials:true, - origin: function (origin, callback) { - if (whitelist.indexOf(origin) !== -1) { - callback(null, true) - } else { - callback(new Error('Not allowed by CORS')) - } - } -} - -app.use(cors(corsOptions)); + credentials: true, + origin: 'https://quiet-9tua.onrender.com', + methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], + allowedHeaders: [ + "Origin", + "Content-Type", + "Accept", + "Authorization", + "X-Requested-With", + ], +}; +app.use('*',cors(corsOptions)); app.use(bodyParser.json()) app.use(express.json()); app.use(express.urlencoded({extended:true})); diff --git a/frontend/.gitignore b/frontend/.gitignore index a547bf3..d7de12f 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -12,6 +12,8 @@ dist dist-ssr *.local +.env + # Editor directories and files .vscode/* !.vscode/extensions.json diff --git a/frontend/src/utils/localhost.js b/frontend/src/utils/localhost.js index 9266fdd..eca80c3 100644 --- a/frontend/src/utils/localhost.js +++ b/frontend/src/utils/localhost.js @@ -1,2 +1,2 @@ -const baseAddress = 'http://localhost:3000/' +const baseAddress = "http://api.bequiet.live/" export default baseAddress; \ No newline at end of file From 0d64007a7cd59f47abc445a3754c0f6b4df78cf2 Mon Sep 17 00:00:00 2001 From: Devesh Shukla Date: Fri, 16 Aug 2024 21:10:15 +0530 Subject: [PATCH 2/3] http->https --- frontend/src/utils/localhost.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/utils/localhost.js b/frontend/src/utils/localhost.js index eca80c3..4978c86 100644 --- a/frontend/src/utils/localhost.js +++ b/frontend/src/utils/localhost.js @@ -1,2 +1,2 @@ -const baseAddress = "http://api.bequiet.live/" -export default baseAddress; \ No newline at end of file +const baseAddress = "https://api.bequiet.live/" +export default baseAddress; From 49b4bbe7e9952d10ccdb4809c21c40d91d3b8be6 Mon Sep 17 00:00:00 2001 From: Devesh Shukla Date: Sat, 17 Aug 2024 18:02:18 +0530 Subject: [PATCH 3/3] corsOrigin --- .github/workflows/deploy.yml | 22 +++++++++++----------- backend/src/server.js | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0bd5cd9..c6944c6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -32,14 +32,14 @@ jobs: - name: Verify Pushed Image run: docker pull imdeveshshukla/quiet-backend - # - name: Deploy to EC2 - # uses: appleboy/ssh-action@master working - # with: - # host: ${{ secrets.SSH_HOST }} - # username: ${{ secrets.SSH_USERNAME }} - # key: ${{ secrets.SSH_KEY }} - # script: | - # sudo docker pull imdeveshshukla/quiet-backend:latest - # sudo docker stop web-app || true - # sudo docker rm web-app || true - # sudo docker run --env-file .env --restart-always -d --name web-app -p 3000:3000 imdeveshshukla/quiet-backend:latest \ No newline at end of file + - name: Deploy + uses: appleboy/ssh-action@master #working + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_KEY }} + script: | + sudo docker pull imdeveshshukla/quiet-backend:latest + sudo docker stop web-app || true + sudo docker rm web-app || true + sudo docker run --env-file .env --restart always -d --name web-app -p 3000:3000 imdeveshshukla/quiet-backend:latest \ No newline at end of file diff --git a/backend/src/server.js b/backend/src/server.js index e20b951..ad41d38 100644 --- a/backend/src/server.js +++ b/backend/src/server.js @@ -17,7 +17,7 @@ const app = express() const port = 3000 const corsOptions = { credentials: true, - origin: 'https://quiet-9tua.onrender.com', + origin: 'https://www.bequiet.live', methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], allowedHeaders: [ "Origin",