小编mmh*_*mmh的帖子

天蓝色应用服务上的角度应用 - 从资源文件夹加载配置文件时出现404错误

我试图在azure app服务平台(windows机器)上部署一个角度6应用程序.该应用程序本身只是一个新的角度应用程序(从新的appname生成的基本代码).我在本教程后面添加了一些次要代码,以便使用配置文件并在vsts发布管道中利用变量替换 - 管理带有vsts的角度应用程序的设置.

这些是我对生成的应用程序所做的代码更改.在app.module.ts中

export function initializeAppSettings(appSettings: AppSettings) {
  return () => appSettings.load();
}
Run Code Online (Sandbox Code Playgroud)

...

providers: [AppSettings, {
    provide: APP_INITIALIZER,
    useFactory: initializeAppSettings,
    deps: [AppSettings],
    multi: true
  }]
Run Code Online (Sandbox Code Playgroud)

对于我的appsettings.ts文件

export interface AppConfiguration {
  apiUrl: string;
}

@Injectable()
export class AppSettings {
  static config: AppConfiguration;

  constructor(private http: HttpClient) {}

  load(): Promise<any> {
    const appSettingsJson = environment.production ? 'assets/appsettings.json' : 'assets/appsettings.local.json';
    return new Promise<any>(((resolve, reject) => {
      this.http.get<AppConfiguration>(appSettingsJson)
        .toPromise()
        .then(result => {
          AppSettings.config = result;
          resolve();
        }).catch(reason => {
          reject(`unable to …
Run Code Online (Sandbox Code Playgroud)

azure node.js http-status-code-404 azure-devops angular

3
推荐指数
1
解决办法
1756
查看次数