diff --git a/.github/workflows/prod_edventure.yml b/.github/workflows/prod_edventure.yml new file mode 100644 index 0000000..b67d0ff --- /dev/null +++ b/.github/workflows/prod_edventure.yml @@ -0,0 +1,71 @@ +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and deploy Node.js app to Azure Web App - edventure + +on: + push: + branches: + - prod + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js version + uses: actions/setup-node@v3 + with: + node-version: '20.x' + + - name: npm install, build, and test + run: | + npm install + npm run build --if-present + npm run test --if-present + + - name: Zip artifact for deployment + run: zip release.zip ./* -r + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v3 + with: + name: node-app + path: release.zip + + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + permissions: + id-token: write #This is required for requesting the JWT + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v3 + with: + name: node-app + + - name: Unzip artifact for deployment + run: unzip release.zip + + - name: Login to Azure + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_88218DBA312445B8A13AEBE0D933F231 }} + tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_21F46878DA51410284E00CBFA9599ED6 }} + subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_1D65A3A7864F406EB63FC0EE3A38308E }} + + - name: 'Deploy to Azure Web App' + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'edventure' + slot-name: 'Production' + package: . + \ No newline at end of file diff --git a/.idx/dev.nix b/.idx/dev.nix new file mode 100644 index 0000000..2ce0434 --- /dev/null +++ b/.idx/dev.nix @@ -0,0 +1,55 @@ +# To learn more about how to use Nix to configure your environment +# see: https://developers.google.com/idx/guides/customize-idx-env +{ pkgs, ... }: { + # Which nixpkgs channel to use. + channel = "stable-23.11"; # or "unstable" + + # Use https://search.nixos.org/packages to find packages + packages = [ + # pkgs.go + # pkgs.python311 + # pkgs.python311Packages.pip + # pkgs.nodejs_20 + # pkgs.nodePackages.nodemon + ]; + + # Sets environment variables in the workspace + env = {}; + idx = { + # Search for the extensions you want on https://open-vsx.org/ and use "publisher.id" + extensions = [ + # "vscodevim.vim" + ]; + + # Enable previews + previews = { + enable = true; + previews = { + # web = { + # # Example: run "npm run dev" with PORT set to IDX's defined port for previews, + # # and show it in IDX's web preview panel + # command = ["npm" "run" "dev"]; + # manager = "web"; + # env = { + # # Environment variables to set for your server + # PORT = "$PORT"; + # }; + # }; + }; + }; + + # Workspace lifecycle hooks + workspace = { + # Runs when a workspace is first created + onCreate = { + # Example: install JS dependencies from NPM + # npm-install = "npm install"; + }; + # Runs when the workspace is (re)started + onStart = { + # Example: start a background task to watch and re-build backend code + # watch-backend = "npm run watch-backend"; + }; + }; + }; +} diff --git a/Backend/src/index.ts b/Backend/src/index.ts index fe4a413..73b413f 100644 --- a/Backend/src/index.ts +++ b/Backend/src/index.ts @@ -10,6 +10,6 @@ app.use(express.json()) app.use(cookieparser()) app.use("/api/v1",rootRouter) -app.listen(3000,function() { - console.log("Listening on Port: 3000") -}) \ No newline at end of file +app.listen(process.env.PORT || 8080, function() { + console.log(`Listening on Port: ${process.env.PORT || 8080}`); +}); \ No newline at end of file diff --git a/EdVenture-FrontEnd/src/app/components/dashboard/chat/chat.component.ts b/EdVenture-FrontEnd/src/app/components/dashboard/chat/chat.component.ts index 1e6f8aa..cba1157 100644 --- a/EdVenture-FrontEnd/src/app/components/dashboard/chat/chat.component.ts +++ b/EdVenture-FrontEnd/src/app/components/dashboard/chat/chat.component.ts @@ -23,7 +23,7 @@ export class ChatComponent implements OnInit { setInterval(() => { this.http - .get('http://localhost:3000/api/v1/group/getmsgs', { + .get('http://edventure.azurewebsites.net/api/v1/group/getmsgs', { params: { loggedInUsername: this.loggedInUsername } }) .subscribe((response: any) => { @@ -42,7 +42,7 @@ export class ChatComponent implements OnInit { } // create the body of the request this.http - .post('http://localhost:3000/api/v1/group/msgGroup', body) + .post('http://edventure.azurewebsites.net/api/v1/group/msgGroup', body) .subscribe((response: any) => {}) this.content = '' // clear the input field diff --git a/EdVenture-FrontEnd/src/app/components/dashboard/dashboard-nav/dashboard-nav.component.ts b/EdVenture-FrontEnd/src/app/components/dashboard/dashboard-nav/dashboard-nav.component.ts index 600e300..93f2794 100644 --- a/EdVenture-FrontEnd/src/app/components/dashboard/dashboard-nav/dashboard-nav.component.ts +++ b/EdVenture-FrontEnd/src/app/components/dashboard/dashboard-nav/dashboard-nav.component.ts @@ -15,7 +15,7 @@ export class DashboardNavComponent { constructor(public http: HttpClient, private router: Router) { } logout() { - this.http.get("http://localhost:3000/api/v1/user/logout",{withCredentials:true}).subscribe( + this.http.get("http://edventure.azurewebsites.net/api/v1/user/logout",{withCredentials:true}).subscribe( () => { // Success: delete all cookies for domain 'localhost' and path '/' // Assuming you're using ngx-cookie-service diff --git a/EdVenture-FrontEnd/src/app/components/home/home.component.ts b/EdVenture-FrontEnd/src/app/components/home/home.component.ts index e0b1f6c..7008724 100644 --- a/EdVenture-FrontEnd/src/app/components/home/home.component.ts +++ b/EdVenture-FrontEnd/src/app/components/home/home.component.ts @@ -20,7 +20,7 @@ export class HomeComponent implements OnInit { } checkCookie(): void { - this.http.post("http://localhost:3000/api/v1/user/checkCookie", {}, {withCredentials: true}).subscribe( + this.http.post("http://edventure.azurewebsites.net/api/v1/user/checkCookie", {}, {withCredentials: true}).subscribe( (response: any) => { if(response.msg == "Log in Success") this.router.navigate(['/dashboard']) diff --git a/EdVenture-FrontEnd/src/app/components/login/login.component.ts b/EdVenture-FrontEnd/src/app/components/login/login.component.ts index a6f9c19..97b1bcd 100644 --- a/EdVenture-FrontEnd/src/app/components/login/login.component.ts +++ b/EdVenture-FrontEnd/src/app/components/login/login.component.ts @@ -32,7 +32,7 @@ export class LoginComponent { this.body.username = form.value.email; this.body.password = form.value.password; this.http - .post('http://localhost:3000/api/v1/user/signin', this.body, {withCredentials: true}) + .post('http://edventure.azurewebsites.net/api/v1/user/signin', this.body, {withCredentials: true}) .subscribe((response: any) => { this.state = response.msg; if(this.state == "Log In Success"){ diff --git a/EdVenture-FrontEnd/src/app/components/signup/signup.component.ts b/EdVenture-FrontEnd/src/app/components/signup/signup.component.ts index 1d5406b..6824467 100644 --- a/EdVenture-FrontEnd/src/app/components/signup/signup.component.ts +++ b/EdVenture-FrontEnd/src/app/components/signup/signup.component.ts @@ -65,7 +65,7 @@ export class SignupComponent { this.userData.email = email; this.setotp.email = email; this.http - .post('http://localhost:3000/api/v1/user/getotp', body) + .post('http://edventure.azurewebsites.net/api/v1/user/getotp', body) .subscribe((response: any) => { this.state = response.msg; }); @@ -86,7 +86,7 @@ export class SignupComponent { this.setotp.method = 'signup'; // Send a request to the server to verify the OTP this.http - .post('http://localhost:3000/api/v1/user/verifyotp', this.setotp) + .post('http://edventure.azurewebsites.net/api/v1/user/verifyotp', this.setotp) .subscribe((response: any) => { console.log(response); this.state = response.msg; @@ -101,7 +101,7 @@ export class SignupComponent { if (form.valid) { this.userData.educational_institute = form.value.college; this.http - .post('http://localhost:3000/api/v1/user/signup', this.userData) + .post('http://edventure.azurewebsites.net/api/v1/user/signup', this.userData) .subscribe((response: any) => { this.state = response.msg; console.log(response) diff --git a/package-lock.json b/package-lock.json index e570a28..dbe2680 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,6 @@ "name": "edventure", "dependencies": { "@types/argon2": "^0.15.0", - "@types/cookie-parser": "^1.4.7", "@types/cors": "^2.8.17", "@types/express": "^4.17.21", "@types/jsonwebtoken": "^9.0.6", @@ -16,16 +15,19 @@ "@types/otp-generator": "^4.0.2", "@types/ws": "^8.5.10", "argon2": "^0.40.1", - "cookie-parser": "^1.4.6", "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.19.2", "jsonwebtoken": "^9.0.2", "nodemailer": "^6.9.13", "otp-generator": "^4.0.1", - "typescript": "^5.4.5", + "typescript": "^5.5.3", "ws": "^8.16.0", "zod": "^3.22.4" + }, + "devDependencies": { + "@types/cookie-parser": "^1.4.7", + "cookie-parser": "^1.4.6" } }, "node_modules/@mongodb-js/saslprep": { @@ -74,6 +76,7 @@ "version": "1.4.7", "resolved": "https://registry.npmjs.org/@types/cookie-parser/-/cookie-parser-1.4.7.tgz", "integrity": "sha512-Fvuyi354Z+uayxzIGCwYTayFKocfV7TuDYZClCdIP9ckhvAu/ixDtCB6qx2TT0FKjPLf1f3P/J1rgf6lPs64mw==", + "dev": true, "dependencies": { "@types/express": "*" } @@ -330,6 +333,7 @@ "version": "1.4.6", "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.6.tgz", "integrity": "sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA==", + "dev": true, "dependencies": { "cookie": "0.4.1", "cookie-signature": "1.0.6" @@ -342,6 +346,7 @@ "version": "0.4.1", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz", "integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==", + "dev": true, "engines": { "node": ">= 0.6" } diff --git a/package.json b/package.json index 391093b..84195a4 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,11 @@ "name": "edventure", "scripts": { "Frontend": "cd EdVenture-FrontEnd && ng serve", - "Backend": "cd Backend && npx tsc && cd dist && node index.js" + "Backend": "cd Backend && npx tsc && cd dist && node index.js", + "build": "cd Backend && npx tsc" }, "dependencies": { "@types/argon2": "^0.15.0", - "@types/cookie-parser": "^1.4.7", "@types/cors": "^2.8.17", "@types/express": "^4.17.21", "@types/jsonwebtoken": "^9.0.6", @@ -15,15 +15,18 @@ "@types/otp-generator": "^4.0.2", "@types/ws": "^8.5.10", "argon2": "^0.40.1", - "cookie-parser": "^1.4.6", "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.19.2", "jsonwebtoken": "^9.0.2", "nodemailer": "^6.9.13", "otp-generator": "^4.0.1", + "typescript": "^5.5.3", "ws": "^8.16.0", "zod": "^3.22.4", "typescript": "^5.4.5" + "devDependencies": { + "@types/cookie-parser": "^1.4.7", + "cookie-parser": "^1.4.6" } }