Skip to content

Commit

Permalink
fix: module inject error
Browse files Browse the repository at this point in the history
  • Loading branch information
scarqin committed Jun 23, 2022
1 parent 800ca8e commit 8cd2807
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 42 deletions.
9 changes: 5 additions & 4 deletions src/workbench/browser/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import { EnvState } from './shared/store/env.state';
import { UpgradeModule } from '@angular/upgrade/static';
import { MessageService } from './shared/services/message';
import { IndexedDBStorage } from 'eo/workbench/browser/src/app/shared/services/storage/IndexedDB/lib/';
import { HttpStorage, BaseUrlInterceptor } from 'eo/workbench/browser/src/app/shared/services/storage/http/lib';
import { HttpStorage } from 'eo/workbench/browser/src/app/shared/services/storage/http/lib';
import { StorageService } from 'eo/workbench/browser/src/app/shared/services/storage';
import { RemoteService } from 'eo/workbench/browser/src/app/shared/services/remote/remote.service';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalService } from 'ng-zorro-antd/modal';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { BaseUrlInterceptor } from 'eo/workbench/browser/src/app/shared/services/storage/http/lib/baseUrl.service';

@NgModule({
declarations: [AppComponent],
Expand All @@ -37,9 +38,9 @@ import { HTTP_INTERCEPTORS } from '@angular/common/http';
NgxsModule.forRoot([EnvState]),
],
providers: [
StorageService,
RemoteService,
MessageService,
StorageService,
IndexedDBStorage,
HttpStorage,
NzMessageService,
Expand All @@ -49,9 +50,9 @@ import { HTTP_INTERCEPTORS } from '@angular/common/http';
useFactory: (i) => i.get('$rootScope'),
deps: ['$injector'],
},
{ provide: HTTP_INTERCEPTORS, useClass: BaseUrlInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass:BaseUrlInterceptor, multi: true },
],
// schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
bootstrap: [AppComponent],
})
export class AppModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import { NzDescriptionsModule } from 'ng-zorro-antd/descriptions';
import { NzTagModule } from 'ng-zorro-antd/tag';
import { NzDividerModule } from 'ng-zorro-antd/divider';
import { NzTreeModule } from 'ng-zorro-antd/tree';
import { ShadowDomEncapsulationComponent } from 'eo/workbench/browser/src/app/shared/components/shadow/shadow-dom-encapsulation.component';
import { SharedModule } from 'eo/workbench/browser/src/app/shared/shared.module';

@NgModule({
imports: [
SharedModule,
FormsModule,
NzTabsModule,
NzTagModule,
Expand All @@ -33,6 +34,6 @@ import { ShadowDomEncapsulationComponent } from 'eo/workbench/browser/src/app/sh
NzTreeModule,
],
providers: [ExtensionService],
declarations: [ExtensionComponent, ExtensionListComponent, ExtensionDetailComponent, ShadowDomEncapsulationComponent],
declarations: [ExtensionComponent, ExtensionListComponent, ExtensionDetailComponent],
})
export class ExtensionModule {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { ElectronService } from '../../../core/services';
import { ElectronService } from '../../core/services';
import { ModuleInfo } from 'eo/platform/node/extension-manager';
import { MessageService } from '../../../shared/services/message';
import { MessageService } from '../../shared/services/message';
import { NzConfigService } from 'ng-zorro-antd/core/config';
import { RemoteService } from 'eo/workbench/browser/src/app/shared/services/remote/remote.service';

Expand Down
14 changes: 14 additions & 0 deletions src/workbench/browser/src/app/pages/navbar/navbar.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { NzDropDownModule } from 'ng-zorro-antd/dropdown';
import { NzToolTipModule } from 'ng-zorro-antd/tooltip';
import { NavbarComponent } from 'eo/workbench/browser/src/app/pages/navbar/navbar.component';
import { SettingModule } from 'eo/workbench/browser/src/app/shared/components/setting/setting.module';
import { CommonModule } from '@angular/common';

@NgModule({
imports: [CommonModule,NzDropDownModule,NzToolTipModule, SettingModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [NavbarComponent],
exports: [NavbarComponent],
})
export class NavbarModule {}
3 changes: 2 additions & 1 deletion src/workbench/browser/src/app/pages/pages.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { SettingModule } from '../shared/components/setting/setting.module';
import { PagesComponent } from './pages.component';
import { SharedModule } from '../shared/shared.module';
import { NzIconModule } from 'ng-zorro-antd/icon';
import { NavbarModule } from 'eo/workbench/browser/src/app/pages/navbar/navbar.module';

@NgModule({
imports: [PagesRoutingModule, SettingModule, CommonModule, SharedModule, NzIconModule, NavbarModule],
declarations: [PagesComponent],
imports: [PagesRoutingModule, SettingModule, CommonModule, SharedModule, NzIconModule],
exports: [],
})
export class PagesModule {}
1 change: 0 additions & 1 deletion src/workbench/browser/src/app/shared/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './toolbar/toolbar.component';
export * from './toolbar/select-theme/select-theme.component';
export * from './sidebar/sidebar.component';
export * from './navbar/navbar.component';
export * from './page-not-found/page-not-found.component';
export * from './about/about.component';
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { NzDescriptionsModule } from 'ng-zorro-antd/descriptions';
import { ElectronService } from '../../../core/services';
import { SelectThemeComponent } from 'eo/workbench/browser/src/app/shared/components/toolbar/select-theme/select-theme.component';
import { AboutComponent } from 'eo/workbench/browser/src/app/shared/components/about/about.component';
import { ShadowDomEncapsulationComponent } from 'eo/workbench/browser/src/app/shared/components/shadow/shadow-dom-encapsulation.component';
import { SharedModule } from 'eo/workbench/browser/src/app/shared/shared.module';

const ANTDMODULES = [
NzModalModule,
Expand All @@ -45,8 +45,8 @@ const ANTDMODULES = [
NzDescriptionsModule,
];
@NgModule({
declarations: [SettingComponent, SelectThemeComponent, AboutComponent, ShadowDomEncapsulationComponent],
imports: [FormsModule, ReactiveFormsModule, CommonModule, ...ANTDMODULES],
declarations: [SettingComponent, SelectThemeComponent, AboutComponent],
imports: [FormsModule, ReactiveFormsModule,SharedModule, CommonModule, ...ANTDMODULES],
exports: [SettingComponent, SelectThemeComponent],
providers: [ElectronService],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { filter, map, Observable } from "rxjs";
const protocolReg = new RegExp('^(http|https)://');

// implements StorageInterface
@Injectable()
export class BaseUrlInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const { url = '', token = '' } = window.eo?.getModuleSettings?.('eoapi-common.remoteServer') || {};
req = req.clone({
url: protocolReg.test(req.url) ? req.url : url + req.url,
headers: req.headers.append('x-api-key', token),
});

return next.handle(req).pipe(
filter((event) => event instanceof HttpResponse && [200, 201].includes(event.status)),
map((event: HttpResponse<any>) => event.clone({ body: { status: 200, data: event.body.data } }))
);
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
import { HttpClient, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { env } from 'process';
import { Observable, map, filter } from 'rxjs';
import { Observable} from 'rxjs';
import {
Project,
Environment,
Group,
ApiData,
ApiTestHistory,
StorageInterface,
StorageItem,
ApiMockEntity,
} from '../../index.model';

const protocolReg = new RegExp('^(http|https)://');

// implements StorageInterface
@Injectable()
export class BaseUrlInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const { url = '', token = '' } = window.eo?.getModuleSettings?.('eoapi-common.remoteServer') || {};
req = req.clone({
url: protocolReg.test(req.url) ? req.url : url + req.url,
headers: req.headers.append('x-api-key', token),
});

return next.handle(req).pipe(
filter((event) => event instanceof HttpResponse && [200, 201].includes(event.status)),
map((event: HttpResponse<any>) => event.clone({ body: { status: 200, data: event.body.data } }))
);
}
}
@Injectable()
export class HttpStorage implements StorageInterface {
constructor(private http: HttpClient) {
Expand Down
9 changes: 3 additions & 6 deletions src/workbench/browser/src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { PageNotFoundComponent, ToolbarComponent, SidebarComponent, NavbarComponent } from './components';
import { PageNotFoundComponent, ToolbarComponent, SidebarComponent } from './components';
import { WebviewDirective } from './directives';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

import { NzDrawerModule } from 'ng-zorro-antd/drawer';
import { NzModalModule } from 'ng-zorro-antd/modal';
import { NzRadioModule } from 'ng-zorro-antd/radio';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzIconModule } from 'ng-zorro-antd/icon';
Expand All @@ -22,12 +21,10 @@ import { ModalService } from './services/modal.service';
import { PageBlankComponent } from './components/page-blank/page-blank.component';
import { PageFeaturePreviewComponent } from './components/page-feature-preview/page-feature-preview.component';
import { RouterModule } from '@angular/router';
import { SettingModule } from 'eo/workbench/browser/src/app/shared/components/setting/setting.module';

const COMPONENTS = [ToolbarComponent, SidebarComponent, NavbarComponent, PageNotFoundComponent];
import { ShadowDomEncapsulationComponent } from 'eo/workbench/browser/src/app/shared/components/shadow/shadow-dom-encapsulation.component';
const COMPONENTS = [ToolbarComponent, ShadowDomEncapsulationComponent, SidebarComponent, PageNotFoundComponent];
@NgModule({
imports: [
SettingModule,
CommonModule,
FormsModule,
RouterModule,
Expand Down
2 changes: 1 addition & 1 deletion src/workbench/browser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"emitDecoratorMetadata": false,
"experimentalDecorators": true,
"baseUrl": "../../../",
"paths": {
Expand Down

0 comments on commit 8cd2807

Please sign in to comment.