Skip to content

Commit

Permalink
Added new Angular configuration for codespaces
Browse files Browse the repository at this point in the history
Added CORS control support for codespaces
  • Loading branch information
Tzahi12345 committed Dec 3, 2023
1 parent 75cbe4d commit 4bf03bf
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 3 deletions.
11 changes: 11 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
}
]
},
"codespaces": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.codespaces.ts"
}
]
},
"es": {
"localize": ["es"]
}
Expand All @@ -83,6 +91,9 @@
},
"es": {
"browserTarget": "youtube-dl-material:build:es"
},
"codespaces": {
"browserTarget": "youtube-dl-material:build:codespaces"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/app/posts.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}`
Expand Down
9 changes: 9 additions & 0 deletions src/environments/environment.codespaces.ts
Original file line number Diff line number Diff line change
@@ -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
};
3 changes: 2 additions & 1 deletion src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const environment = {
production: true
production: true,
codespaces: false
};
3 changes: 2 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

0 comments on commit 4bf03bf

Please sign in to comment.