angular proxy issues getting index.html or cors error
Hey everybody i've some issues with my angular client.
whenever i do a post request to my spring backend using a Proxy like this...
{
"/api": {
"target": "http://localhost:3000",
"secure": false,
"changeOrigin": true,
"pathRewrite": {
"^/api": ""
}
}
}
If I set changeOrigin to False then it works on backend as expected. The login works well. The only thing that's weird is the response in the angular client. Instead of getting the original response from the backend Server I am getting the content of my index.html file of my angular App. The response in httpClient.post.subscribe(...) is just the content of the Index.html File.
Then I tried to set changeOrigin to true. But then nothing works anymore.
I get a cors error and my Spring Backend denies the request. Why that?
I thought when I wanted cors being disabled on backend then using a proxy is the way to go. At least when it comes to setting up the dev environment.
On backend side my spring security looks like this:
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable().exceptionHandling()
.authenticationEntryPoint(
(request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)
)
.and().authorizeRequests()
.antMatchers("/login", "/authorize").permitAll()
.anyRequest().authenticated()
.and().formLogin().permitAll();//.and().httpBasic();
}
In my browser the client shows me the following errormessage:
spring angular proxy cors
|
show 1 more comment
Hey everybody i've some issues with my angular client.
whenever i do a post request to my spring backend using a Proxy like this...
{
"/api": {
"target": "http://localhost:3000",
"secure": false,
"changeOrigin": true,
"pathRewrite": {
"^/api": ""
}
}
}
If I set changeOrigin to False then it works on backend as expected. The login works well. The only thing that's weird is the response in the angular client. Instead of getting the original response from the backend Server I am getting the content of my index.html file of my angular App. The response in httpClient.post.subscribe(...) is just the content of the Index.html File.
Then I tried to set changeOrigin to true. But then nothing works anymore.
I get a cors error and my Spring Backend denies the request. Why that?
I thought when I wanted cors being disabled on backend then using a proxy is the way to go. At least when it comes to setting up the dev environment.
On backend side my spring security looks like this:
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable().exceptionHandling()
.authenticationEntryPoint(
(request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)
)
.and().authorizeRequests()
.antMatchers("/login", "/authorize").permitAll()
.anyRequest().authenticated()
.and().formLogin().permitAll();//.and().httpBasic();
}
In my browser the client shows me the following errormessage:
spring angular proxy cors
Try"logLevel": "debug"
and see if it helps figure out what happens
– YoukouleleY
Nov 15 '18 at 15:02
Also when you make requests to your backend the URLs arehttp://localhost:4200/api/...
right?
– YoukouleleY
Nov 15 '18 at 15:04
yes requests are going to localhost:4200/api/login a post requests for example
– Chris
Nov 16 '18 at 14:07
I ve turned on debugmode.. it says the request has properly been forwarded to the backend. And even the backend showing it. The only errormessage is within my browser that an access control origin header is missing.
– Chris
Nov 16 '18 at 14:18
So you are having an error message concerning the access control origin when your frontend is served onlocalhost:4200
and your backend too?
– YoukouleleY
Nov 16 '18 at 16:36
|
show 1 more comment
Hey everybody i've some issues with my angular client.
whenever i do a post request to my spring backend using a Proxy like this...
{
"/api": {
"target": "http://localhost:3000",
"secure": false,
"changeOrigin": true,
"pathRewrite": {
"^/api": ""
}
}
}
If I set changeOrigin to False then it works on backend as expected. The login works well. The only thing that's weird is the response in the angular client. Instead of getting the original response from the backend Server I am getting the content of my index.html file of my angular App. The response in httpClient.post.subscribe(...) is just the content of the Index.html File.
Then I tried to set changeOrigin to true. But then nothing works anymore.
I get a cors error and my Spring Backend denies the request. Why that?
I thought when I wanted cors being disabled on backend then using a proxy is the way to go. At least when it comes to setting up the dev environment.
On backend side my spring security looks like this:
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable().exceptionHandling()
.authenticationEntryPoint(
(request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)
)
.and().authorizeRequests()
.antMatchers("/login", "/authorize").permitAll()
.anyRequest().authenticated()
.and().formLogin().permitAll();//.and().httpBasic();
}
In my browser the client shows me the following errormessage:
spring angular proxy cors
Hey everybody i've some issues with my angular client.
whenever i do a post request to my spring backend using a Proxy like this...
{
"/api": {
"target": "http://localhost:3000",
"secure": false,
"changeOrigin": true,
"pathRewrite": {
"^/api": ""
}
}
}
If I set changeOrigin to False then it works on backend as expected. The login works well. The only thing that's weird is the response in the angular client. Instead of getting the original response from the backend Server I am getting the content of my index.html file of my angular App. The response in httpClient.post.subscribe(...) is just the content of the Index.html File.
Then I tried to set changeOrigin to true. But then nothing works anymore.
I get a cors error and my Spring Backend denies the request. Why that?
I thought when I wanted cors being disabled on backend then using a proxy is the way to go. At least when it comes to setting up the dev environment.
On backend side my spring security looks like this:
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable().exceptionHandling()
.authenticationEntryPoint(
(request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)
)
.and().authorizeRequests()
.antMatchers("/login", "/authorize").permitAll()
.anyRequest().authenticated()
.and().formLogin().permitAll();//.and().httpBasic();
}
In my browser the client shows me the following errormessage:
spring angular proxy cors
spring angular proxy cors
edited Nov 16 '18 at 18:38
Chris
asked Nov 14 '18 at 19:52
ChrisChris
1721314
1721314
Try"logLevel": "debug"
and see if it helps figure out what happens
– YoukouleleY
Nov 15 '18 at 15:02
Also when you make requests to your backend the URLs arehttp://localhost:4200/api/...
right?
– YoukouleleY
Nov 15 '18 at 15:04
yes requests are going to localhost:4200/api/login a post requests for example
– Chris
Nov 16 '18 at 14:07
I ve turned on debugmode.. it says the request has properly been forwarded to the backend. And even the backend showing it. The only errormessage is within my browser that an access control origin header is missing.
– Chris
Nov 16 '18 at 14:18
So you are having an error message concerning the access control origin when your frontend is served onlocalhost:4200
and your backend too?
– YoukouleleY
Nov 16 '18 at 16:36
|
show 1 more comment
Try"logLevel": "debug"
and see if it helps figure out what happens
– YoukouleleY
Nov 15 '18 at 15:02
Also when you make requests to your backend the URLs arehttp://localhost:4200/api/...
right?
– YoukouleleY
Nov 15 '18 at 15:04
yes requests are going to localhost:4200/api/login a post requests for example
– Chris
Nov 16 '18 at 14:07
I ve turned on debugmode.. it says the request has properly been forwarded to the backend. And even the backend showing it. The only errormessage is within my browser that an access control origin header is missing.
– Chris
Nov 16 '18 at 14:18
So you are having an error message concerning the access control origin when your frontend is served onlocalhost:4200
and your backend too?
– YoukouleleY
Nov 16 '18 at 16:36
Try
"logLevel": "debug"
and see if it helps figure out what happens– YoukouleleY
Nov 15 '18 at 15:02
Try
"logLevel": "debug"
and see if it helps figure out what happens– YoukouleleY
Nov 15 '18 at 15:02
Also when you make requests to your backend the URLs are
http://localhost:4200/api/...
right?– YoukouleleY
Nov 15 '18 at 15:04
Also when you make requests to your backend the URLs are
http://localhost:4200/api/...
right?– YoukouleleY
Nov 15 '18 at 15:04
yes requests are going to localhost:4200/api/login a post requests for example
– Chris
Nov 16 '18 at 14:07
yes requests are going to localhost:4200/api/login a post requests for example
– Chris
Nov 16 '18 at 14:07
I ve turned on debugmode.. it says the request has properly been forwarded to the backend. And even the backend showing it. The only errormessage is within my browser that an access control origin header is missing.
– Chris
Nov 16 '18 at 14:18
I ve turned on debugmode.. it says the request has properly been forwarded to the backend. And even the backend showing it. The only errormessage is within my browser that an access control origin header is missing.
– Chris
Nov 16 '18 at 14:18
So you are having an error message concerning the access control origin when your frontend is served on
localhost:4200
and your backend too?– YoukouleleY
Nov 16 '18 at 16:36
So you are having an error message concerning the access control origin when your frontend is served on
localhost:4200
and your backend too?– YoukouleleY
Nov 16 '18 at 16:36
|
show 1 more comment
1 Answer
1
active
oldest
votes
to solve my problem I activated cross origin tokens on backend side.
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
}
I thought that wouldn't be necessary if I used a proxy.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307819%2fangular-proxy-issues-getting-index-html-or-cors-error%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
to solve my problem I activated cross origin tokens on backend side.
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
}
I thought that wouldn't be necessary if I used a proxy.
add a comment |
to solve my problem I activated cross origin tokens on backend side.
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
}
I thought that wouldn't be necessary if I used a proxy.
add a comment |
to solve my problem I activated cross origin tokens on backend side.
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
}
I thought that wouldn't be necessary if I used a proxy.
to solve my problem I activated cross origin tokens on backend side.
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
}
I thought that wouldn't be necessary if I used a proxy.
answered Dec 22 '18 at 10:30
ChrisChris
1721314
1721314
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307819%2fangular-proxy-issues-getting-index-html-or-cors-error%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try
"logLevel": "debug"
and see if it helps figure out what happens– YoukouleleY
Nov 15 '18 at 15:02
Also when you make requests to your backend the URLs are
http://localhost:4200/api/...
right?– YoukouleleY
Nov 15 '18 at 15:04
yes requests are going to localhost:4200/api/login a post requests for example
– Chris
Nov 16 '18 at 14:07
I ve turned on debugmode.. it says the request has properly been forwarded to the backend. And even the backend showing it. The only errormessage is within my browser that an access control origin header is missing.
– Chris
Nov 16 '18 at 14:18
So you are having an error message concerning the access control origin when your frontend is served on
localhost:4200
and your backend too?– YoukouleleY
Nov 16 '18 at 16:36