From 0d62e5e814c0d47e76ce9fe7ede6bfb0913bcaa8 Mon Sep 17 00:00:00 2001 From: Devesh Shukla Date: Sat, 17 Aug 2024 20:00:10 +0530 Subject: [PATCH] somebug --- .github/workflows/build.yml | 9 ++++++--- .github/workflows/deploy.yml | 8 +++----- backend/.env.example | 4 +++- backend/src/controller/user.js | 7 ++++--- backend/src/server.js | 2 +- frontend/src/App.jsx | 4 ++-- frontend/src/utils/localhost.js | 3 ++- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e803337..68015ad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,9 @@ -name: Build on PR +name: Build Quietly on: pull_request: branches: - - build #stopped + - deploy #branch jobs: build: @@ -14,9 +14,12 @@ jobs: uses: actions/setup-node@v3 with: node-version: '20' + - name: Install Dependencies run: npm install + working-directory: ./backend - name: Run Build - run: npm run build + run: npm run deploy + working-directory: ./backend diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c6944c6..a9e44a4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,9 +1,9 @@ -name: Build and Deploy to Docker Hub +name: Continuous Deployment on: push: branches: - - deploy # Adjusted to trigger on pushes to master + - deploy # branch jobs: build-and-push: @@ -12,8 +12,6 @@ jobs: - name: Check Out Repo uses: actions/checkout@v2 - # - name: Prepare Dockerfile - # run: cp ./backend/Dockerfile ./Dockerfile - name: Log in to Docker Hub uses: docker/login-action@v1 @@ -33,7 +31,7 @@ jobs: run: docker pull imdeveshshukla/quiet-backend - name: Deploy - uses: appleboy/ssh-action@master #working + uses: appleboy/ssh-action@master #script with: host: ${{ secrets.SSH_HOST }} username: ${{ secrets.SSH_USERNAME }} diff --git a/backend/.env.example b/backend/.env.example index de1be95..fa7203b 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -5,4 +5,6 @@ CLOUDINARY_API_KEY="" CLOUDINARY_API_SECRET="" SECRET_KEY="" AUTH_EMAIL="" -AUTH_PASS="" \ No newline at end of file +AUTH_PASS="" + +NODE_ENV = "development" \ No newline at end of file diff --git a/backend/src/controller/user.js b/backend/src/controller/user.js index 08161a3..927515c 100644 --- a/backend/src/controller/user.js +++ b/backend/src/controller/user.js @@ -20,6 +20,7 @@ const getUser = async (req, res) => { if (typeof email !== "string") return res.status(404).json({ msg: "invalid username" }); try { + console.log(email) const user = await prisma.user.findUnique({ where: { email: req.params.email, @@ -83,13 +84,13 @@ const getUser = async (req, res) => { }, }, }); - // console.log(user); + console.log(user); - res.status(200).send({ + return res.status(200).send({ user, }); } catch (error) { - res.status(500).json({ + return res.status(500).json({ msg: "Server/Database Error", error: error.message, }); diff --git a/backend/src/server.js b/backend/src/server.js index ad41d38..5fb424c 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://www.bequiet.live', + origin: (process.env.NODE_ENV === 'development')?'http://localhost:5173':'https://www.bequiet.live', methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], allowedHeaders: [ "Origin", diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index e0654d6..1511da8 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -138,9 +138,9 @@ function App() { } } catch (error) { console.log(error); - if (error.response.status == 404) { + if (error.response?.status == 404) { console.log("token not found"); - } else if (error.response.status == 401) { + } else if (error.response?.status == 401) { console.log("Invalid token"); } } diff --git a/frontend/src/utils/localhost.js b/frontend/src/utils/localhost.js index 4978c86..3f261b2 100644 --- a/frontend/src/utils/localhost.js +++ b/frontend/src/utils/localhost.js @@ -1,2 +1,3 @@ -const baseAddress = "https://api.bequiet.live/" +const baseAddress = "http://localhost:3000/" + export default baseAddress;