From 75cbe4d5d0879cd0dd68bab224eb884e37989537 Mon Sep 17 00:00:00 2001 From: Tzahi12345 Date: Sun, 3 Dec 2023 07:39:53 +0000 Subject: [PATCH 1/2] Added codespaces json --- .devcontainer/devcontainer.json | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..99a42303 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,39 @@ +// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node +{ + "name": "Node.js", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/javascript-node:0-18-bullseye", + "features": { + "ghcr.io/devcontainers-contrib/features/jshint:2": {}, + "ghcr.io/devcontainers-contrib/features/angular-cli:2": {}, + "ghcr.io/devcontainers/features/github-cli:1": {} + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [4200, 17442], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "npm install && cd backend && npm install", + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-python.python", + "Angular.ng-template", + "dbaeumer.vscode-eslint", + "waderyan.gitblame", + "42Crunch.vscode-openapi", + "christian-kohler.npm-intellisense", + "redhat.vscode-yaml", + "hbenl.vscode-mocha-test-adapter", + "DavidAnson.vscode-markdownlint" + ] + } + } + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" + } \ No newline at end of file From 4bf03bfd1ab1de5d6bed1e0f8d159b75b3422d21 Mon Sep 17 00:00:00 2001 From: Tzahi12345 Date: Sun, 3 Dec 2023 19:11:21 +0000 Subject: [PATCH 2/2] Added new Angular configuration for codespaces Added CORS control support for codespaces --- angular.json | 11 +++++++++++ backend/app.js | 1 + package.json | 1 + src/app/posts.services.ts | 3 ++- src/environments/environment.codespaces.ts | 9 +++++++++ src/environments/environment.prod.ts | 3 ++- src/environments/environment.ts | 3 ++- 7 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/environments/environment.codespaces.ts diff --git a/angular.json b/angular.json index 8f50ad64..aa316d22 100644 --- a/angular.json +++ b/angular.json @@ -66,6 +66,14 @@ } ] }, + "codespaces": { + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.codespaces.ts" + } + ] + }, "es": { "localize": ["es"] } @@ -83,6 +91,9 @@ }, "es": { "browserTarget": "youtube-dl-material:build:es" + }, + "codespaces": { + "browserTarget": "youtube-dl-material:build:codespaces" } } }, diff --git a/backend/app.js b/backend/app.js index 4bc95842..178fd98e 100644 --- a/backend/app.js +++ b/backend/app.js @@ -565,6 +565,7 @@ function loadConfigValues() { } function getOrigin() { + if (process.env.CODESPACES) return `https://${process.env.CODESPACE_NAME}-4200.${process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}`; return url_domain.origin; } diff --git a/package.json b/package.json index 34858c92..dd93218a 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "scripts": { "ng": "ng", "start": "ng serve", + "codespaces": "ng serve --configuration=codespaces", "build": "ng build --configuration production", "prebuild": "node src/postbuild.mjs", "heroku-postbuild": "npm install --prefix backend", diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts index e1a4af14..7bde6d9e 100644 --- a/src/app/posts.services.ts +++ b/src/app/posts.services.ts @@ -119,6 +119,7 @@ import { import { isoLangs } from './dialogs/user-profile-dialog/locales_list'; import { Title } from '@angular/platform-browser'; import { MatDrawerMode } from '@angular/material/sidenav'; +import { environment } from '../environments/environment'; @Injectable() export class PostsService implements CanActivate { @@ -176,7 +177,7 @@ export class PostsService implements CanActivate { if (isDevMode()) { this.debugMode = true; - this.path = 'http://localhost:17442/api/'; + this.path = !environment.codespaces ? 'http://localhost:17442/api/' : `${window.location.origin.replace('4200', '17442')}/api/`; } this.http_params = `apiKey=${this.auth_token}` diff --git a/src/environments/environment.codespaces.ts b/src/environments/environment.codespaces.ts new file mode 100644 index 00000000..aa9b9859 --- /dev/null +++ b/src/environments/environment.codespaces.ts @@ -0,0 +1,9 @@ +// The file contents for the current environment will overwrite these during build. +// The build system defaults to the dev environment which uses `environment.ts`, but if you do +// `ng build --env=prod` then `environment.prod.ts` will be used instead. +// The list of which env maps to which file can be found in `.angular-cli.json`. + +export const environment = { + production: false, + codespaces: true +}; diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 3612073b..ffe345ed 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,3 +1,4 @@ export const environment = { - production: true + production: true, + codespaces: false }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 4f0114ac..316b8c1c 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,5 +4,6 @@ // The list of which env maps to which file can be found in `.angular-cli.json`. export const environment = { - production: true + production: false, + codespaces: false };