New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
migration to HttpClient #6951
migration to HttpClient #6951
Conversation
… alert-error component accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had quick look from my mobile, will take a closer look later
import { PaginationConfig } from './blocks/config/uib-pagination.config'; | ||
import { HTTP_INTERCEPTORS } from '@angular/common/http'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this import above local imports
import { BrowserModule } from '@angular/platform-browser'; | ||
import { Ng2Webstorage } from 'ngx-webstorage'; | ||
import { Ng2Webstorage<%_ if (authenticationType === 'jwt') { _%>, LocalStorageService, SessionStorageService <%_ } _%> } from 'ngx-webstorage'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inline template should use <% %>
syntax
import { AuthExpiredInterceptor } from './blocks/interceptor/auth-expired.interceptor'; | ||
import { ErrorHandlerInterceptor } from './blocks/interceptor/errorhandler.interceptor'; | ||
import { NotificationInterceptor } from './blocks/interceptor/notification.interceptor'; | ||
import { JhiEventManager } from 'ng-jhipster'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put this import above local imports along with other library imports
} | ||
|
||
get(): Observable<any> { | ||
return this.http.get(SERVER_API_URL + 'management/configprops').map((res: Response) => { | ||
return this.http.get('management/configprops', { observe: 'response' }).map((res: HttpResponse<any>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the server api url removed?
|
||
return this.http.post(SERVER_API_URL + 'api/authentication', data, { headers }); | ||
return this.http.post(SERVER_API_URL + 'api/authentication', data, { headers: headers}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why switched from shorthand?
<%_ if (authenticationType === 'jwt' || authenticationType === 'uaa') { _%> | ||
{ | ||
provide: HTTP_INTERCEPTORS, | ||
useFactory: (injector) => new AuthExpiredInterceptor(injector), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked, this part? (I am not sure)AOT is handling this correctly in the new version...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we use useClass
here?
@@ -30,10 +30,10 @@ export class SessionsService { | |||
constructor(private http: Http) { } | |||
|
|||
findAll(): Observable<Session[]> { | |||
return this.http.get(this.resourceUrl).map((res: Response) => res.json()); | |||
return this.http.get<Session[]>(this.resourceUrl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really liked this one 👍 It clearly states what is gonna be there ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tried to type everything i stubled over not sure though if i really did it eveywhere so far
}, (err: any) => { | ||
if (err instanceof HttpErrorResponse) { | ||
if (err.status === 401) { | ||
<% if (authenticationType === 'jwt') { %> | ||
const loginService: LoginService = this.injector.get(LoginService); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any possibility to remove the injector completely? This looks like hacky, can't we inject these services straight
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will try that tomorrow it should at least work for login service not sure what happens with Principal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok tried to remove it and it doesnt work as it woudl create a cyclic dependenncy becuase login service uses HttpClient that uses the interceptor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, Injector is used to avoid cyclic dependency hell in angular
} | ||
|
||
const token = this.localStorage.retrieve('authenticationToken') || this.sessionStorage.retrieve('authenticationToken'); | ||
if (!!token) { | ||
options.headers.append('Authorization', 'Bearer ' + token); | ||
request = request.clone({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it mutate the entire headers? If there are any headers set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no according to this implementation https://github.com/angular/angular/blob/5.1.3/packages/common/http/src/request.ts#L67-L385
setHeaders adds the header. headers would mutate all headers.
badnaming on angular site though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was confused too... so just wanted to make sure...
} | ||
|
||
find(login: string): Observable<User> { | ||
return this.http.get(`${this.resourceUrl}/${login}`).map((res: Response) => res.json()); | ||
return this.http.get(`${this.resourceUrl}/${login}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get<User>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep missed it here like i said not sure if i added types everywhere
@NilsWild awesome work 👍 |
will take a closer look tomorrow 2:05 am now :D |
Yes, impressive work for a 1st contribution, @NilsWild ! |
@NilsWild we would love more inconvenience from you then 😺 |
Failed: Angular could not be found on the page http://localhost:8080/.If this is not an Angular application, you may need to turn off waiting for Angular. any idea what may cause this? |
Hopefully application cannot run on the browser (it should have had some errors) |
Might be a glitch, restarted the build
Thanks & Regards,
Deepu
…On Fri, Jan 12, 2018 at 10:51 AM, Nils Wild ***@***.***> wrote:
Failed: Angular could not be found on the page http://localhost:8080/.If
this is not an Angular application, you may need to turn off waiting for
Angular.
any idea what may cause this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6951 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABDlF0EY9pzfnzIgDv_-lcSrT1igFRnyks5tJysdgaJpZM4RUyHh>
.
|
@NilsWild Please be never sorry when contributing to opensource 👍 This is an amazing work 👍 |
Yes what you did @NilsWild is awesome! Thanks so much. |
Thank you all @deepu105 failed for same reason |
@mraible need your help here, the |
Do you need me to look asap? I prefer not to work on the weekends, but I'm happy to help too. Can it wait until Tuesday? Monday is a holiday in the US.
… On Jan 13, 2018, at 08:33, Deepu K Sasidharan ***@***.***> wrote:
@mraible need your help here, the ngx-mariadb-oauth2-sass-infinispan build is failing and I tried it locally and seems like protractor tests are failing as the keycloak login screen appears as soon as I launch the application, even before clicking sign in, I guess something changed due to the new Angular Http client used here, probably the way interceptors work. Could you take a look?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
build looks good now :D |
@jhipster/developers can somebody take this on a test drive? |
Is that desired behavior? |
Hm... actually i just kept the implementation with some slightly modifications in method parameters (to keep the signature as it is right now) that was discussed in the corresponding issue. As you pass a "req" - the request options as an object - i think it should also be the desired behavior to create httpParams out of those. Just my opinion atm. |
I'm merging this so we have time to check |
@NilsWild both your PR merged. I also released ng-jhipster 0.4.0, so you can upgrade to that and remove angular/http |
Yes thank you for your awesome work!! |
@deepu105 i create a new pull request for that purpose? thanks to everyone for the kind words |
yeah sure please. |
- Use: jhipster/generator-jhipster@26e7ff2 - Migrate to HttpClient: jhipster/generator-jhipster#6951 - Refactor folder: shared -> core
see: #6281
Please make sure the below checklist is followed for Pull Requests.
Travis tests are green
Tests are added where necessary
Documentation is added/updated where necessary
Coding Rules & Commit Guidelines as per our CONTRIBUTING.md document are followed