[英]Angular - SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
This is an Angular application deployed on AWS Amplify这是部署在 AWS Amplify 上的 Angular 应用程序
The app is deployed successfully, however it renders a white screen, and on the console I receive this message:该应用程序已成功部署,但呈现白屏,并且在控制台上我收到此消息:
But I don't know how to solve it.但我不知道如何解决。
This is the service provider:这是服务提供者:
import { Inject, Injectable } from '@angular/core';
import {
CONFIG_TOKEN,
UserService,
EuiAppConfig,
UserDetails,
UserPreferences,
I18nService,
} from '@eui/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of, zip } from 'rxjs';
import { switchMap } from 'rxjs/operators';
@Injectable({
providedIn: 'root',
})
export class AppStarterService {
defaultUserPreferences: UserPreferences;
constructor(
protected userService: UserService,
protected i18nService: I18nService,
@Inject(CONFIG_TOKEN) private config: EuiAppConfig,
protected http: HttpClient,
) {
}
start(): Observable<any> {
return zip(
this.initUserService().pipe(
switchMap((userStatus) => {
console.log(userStatus);
return this.i18nService.init();
}),
),
);
}
/**
* Fetches user details,
* create user: UserState object
* then initialise to the UserService on run time
*/
initUserService(): Observable<any> {
return zip(
this.fetchUserDetails(),
).pipe(
switchMap(([userDetails]) => this.userService.init(userDetails)));
}
/**
* Fetches user details
*/
private fetchUserDetails(): Observable<UserDetails> {
const moduleCoreApi = this.config.modules.core;
const url = `${moduleCoreApi.base}${moduleCoreApi.userDetails}`;
const user = { userId: 'anonymous' };
if (!url) {
return of(user);
}
return this.http.get<UserDetails>(url);
}
}
And from that code, this is the " const moduleCoreApi = this.config.modules.core; " and the " moduleCoreApi.base " part从该代码来看,这是“ const moduleCoreApi = this.config.modules.core; ”和“ moduleCoreApi.base ”部分
import { ModulesConfig } from '@eui/core';
export const MODULES: ModulesConfig = {
core: {
base: '/api',
}
};
This is the environment.prod.ts这是environment.prod.ts
import { EuiEnvConfig } from '@eui/core';
export const environment: EuiEnvConfig = {
production: true,
enableDevToolRedux: false,
envDynamicConfig: {
uri: '/assets/env-json-config.json',
deepMerge: true,
merge: ['modules'],
},
};
And from that code, this the env-json-config.json从该代码中,这是env-json-config.json
{
"modules": {
"core": {
"userDetails": "/user-details"
}
}
}
The issue has been solved thanks to @Harun Yilmaz by updating the api endpoint to this:感谢@Harun Yilmaz,通过将 api 端点更新为:
return this.http.get(url,{responseType: 'text'});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.