Refactor API URLs to use GlobalConstants and update CORS configurations for production
This commit is contained in:
@@ -2,12 +2,13 @@ import { Injectable } from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {User} from '../models/user.model';
|
||||
import {GlobalConstants} from '../global-constants';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AdminModuleService {
|
||||
baseUrl = 'http://localhost:8080/api';
|
||||
baseUrl = GlobalConstants.API_URL;
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ export const routes: Routes = [
|
||||
|
||||
];
|
||||
@NgModule({
|
||||
imports: [RouterModule.forRoot(routes)],//, { useHash: true }
|
||||
imports: [RouterModule.forRoot(routes, { useHash: true}) ],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
export class AppRoutingModule {}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { GlobalConstants } from './global-constants';
|
||||
|
||||
describe('GlobalConstants', () => {
|
||||
it('should create an instance', () => {
|
||||
expect(new GlobalConstants()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
import {environment} from '../environments/environment';
|
||||
|
||||
export class GlobalConstants {
|
||||
|
||||
public static readonly API_URL = (() => {
|
||||
// ... calculate the value and return it
|
||||
|
||||
if(environment.production) {
|
||||
return `${environment.host_name}/api`;
|
||||
}else {
|
||||
return `${environment.host_name}:${environment.port}/api`;
|
||||
}
|
||||
|
||||
})();
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import { environment } from '../../../environments/environment';
|
||||
MatToolbar,
|
||||
MatButton,
|
||||
RouterLink,
|
||||
IconDirective,
|
||||
|
||||
RouterOutlet,
|
||||
CommonModule,
|
||||
MatIcon,
|
||||
@@ -38,8 +38,7 @@ import { environment } from '../../../environments/environment';
|
||||
MatMenu,
|
||||
MatMenuItem,
|
||||
MatTooltip,
|
||||
MatLabel,
|
||||
MatFabButton
|
||||
MatLabel
|
||||
|
||||
],
|
||||
schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
|
||||
|
||||
@@ -2,12 +2,13 @@ import { Injectable } from '@angular/core';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Tutorial} from '../models/tutorial.model';
|
||||
import {GlobalConstants} from '../global-constants';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ModeratorApiService {
|
||||
baseUrl = 'http://localhost:8080/api/moderator';
|
||||
baseUrl = `${GlobalConstants.API_URL}/moderator`;
|
||||
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import {GlobalConstants} from '../global-constants';
|
||||
|
||||
const AUTH_API = 'http://localhost:8080/api/auth/';
|
||||
const AUTH_API = GlobalConstants.API_URL + '/auth/';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
|
||||
@@ -15,6 +16,7 @@ export class AuthService {
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
login(username: string, password: string): Observable<any> {
|
||||
console.log(AUTH_API + 'signin');
|
||||
return this.http.post(AUTH_API + 'signin', {
|
||||
username,
|
||||
password
|
||||
|
||||
@@ -2,8 +2,9 @@ import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Role } from '../models/role';
|
||||
import {GlobalConstants} from '../global-constants';
|
||||
|
||||
const API_URL = 'http://localhost:8080/api/roles';
|
||||
const API_URL = `${GlobalConstants.API_URL}/roles`;
|
||||
|
||||
|
||||
@Injectable({
|
||||
|
||||
@@ -4,13 +4,14 @@ import {Observable} from 'rxjs';
|
||||
import {Tutorial} from '../models/tutorial.model';
|
||||
import {Bean} from '../models/Bean';
|
||||
import {NameValueItem} from '../models/name-value-item';
|
||||
import {GlobalConstants} from '../global-constants';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SystemService {
|
||||
|
||||
baseUrl : string = 'http://localhost:8080/api/system';
|
||||
baseUrl : string = `${GlobalConstants.API_URL}/system`;
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
getDataSourceProperties(): Observable<NameValueItem[]>{
|
||||
|
||||
@@ -2,9 +2,9 @@ import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Tutorial } from '../models/tutorial.model';
|
||||
import {text} from 'node:stream/consumers';
|
||||
import {GlobalConstants} from '../global-constants';
|
||||
|
||||
const baseUrl = 'http://localhost:8080/api/public/tutorials';
|
||||
const baseUrl = `${GlobalConstants.API_URL}/public/tutorials`;
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -2,9 +2,9 @@ import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import {User} from "../models/user.model";
|
||||
import {Tutorial} from "../models/tutorial.model";
|
||||
import {GlobalConstants} from '../global-constants';
|
||||
|
||||
const API_URL = 'http://localhost:8080/api/users';
|
||||
const API_URL = `${GlobalConstants.API_URL}/users`;
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -4,6 +4,7 @@ import {Tutorial} from '../models/tutorial.model';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Image} from '../models/image';
|
||||
import {SpinnerService} from './spinner.service';
|
||||
import {GlobalConstants} from '../global-constants';
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +14,7 @@ import {SpinnerService} from './spinner.service';
|
||||
|
||||
|
||||
export class ZhipuaiImageService {
|
||||
baseUrl : string = 'http://localhost:8080/api/zhipuai';
|
||||
baseUrl : string = `${GlobalConstants.API_URL}/public/zhipuai`;
|
||||
|
||||
constructor(private http: HttpClient,public spinnerService: SpinnerService) {
|
||||
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@
|
||||
<mat-slide-toggle
|
||||
class="example-margin"
|
||||
[checked]="element[column.key]"
|
||||
[disabled]="column.key !== 'toBePublished'"
|
||||
[disabled]="column.key !== 'tobepublished'"
|
||||
(change)="publish(element, $event.checked)"
|
||||
>
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@ import { Injectable } from '@angular/core';
|
||||
import {forkJoin, Observable} from 'rxjs';
|
||||
import {Tutorial} from '../models/tutorial.model';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import {GlobalConstants} from '../global-constants';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserApiService {
|
||||
baseUrl = 'http://localhost:8080/api/user';
|
||||
baseUrl = `${GlobalConstants.API_URL}/user`;
|
||||
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
|
||||
Reference in New Issue
Block a user