when refreshing the page it showing error 404 page not found - angular2-routing

i get the same error even when i enter the URL with absolute path
But with Routing it is working fine
{ path: 'login' , component: LoginComponent },
{ path: 'home' , component: HomeComponent},

It's not generally an issue with angular, this issue occurs if your API uses the same port and when you refresh the page the request will go as Get: Login since your API does not have the matching valid param it will throw 404.
Hence that is displayed in the browser

Related

Behat appends additional url when redirecting

I'm using Symfony 3.4 with FOSUserBundle and Behat for testing.
Config & code:
Behat config:
extensions:
Behat\MinkExtension:
sessions:
default:
symfony2: ~
javascript:
selenium2: ~
browser_name: firefox
show_auto: false
base_url: 'http://my-virutalhost.test'
Behat\Symfony2Extension:
kernel:
env: "acceptance"
debug: "true"
Scenario: I execute enpoint address with wrong redirect code
When I go to the url "/redirect/code1code2"
Then I should be redirected to url "http://some-page-here.com"
/**
* #When /^I go to the url "([^"]+)"$/
*/
public function iGoToTheUrl($url) {
$this->lastResponse = $this->getSession()->visit($url);
$this->getSession()->getDriver()->getContent();
//var_dump($url, $this->getSession()->getDriver()->getCurrentUrl());
}
/**
* Checks, that current page PATH matches regular expression.
*
* #Then /^(?:|I )should be redirected to (?P<pattern>"(?:[^"]|\\")*")$/
*/
public function iAmRedirectedToUrl($pattern) {
$this->assertSession()->addressMatches($this->fixStepArgument($pattern));
}
Problem:
Somehow Behat appends to my redirect url http://some-page-here.com /login from my app, which creates link: http://some-page-here.com/login. I don't know why it creates such address for redirect.
-- EDIT --
When I check the content of page $this->getSession()->getDriver()->getContent() I see code of the login page
-- Edit --
/login - it's my application login
I want to make redirect to
outside page, not in a page inside of my application and check if the final address is the address of the page from outside redirect
My security config:
access_control:
- { path: ^/redirect, role: IS_AUTHENTICATED_ANONYMOUSLY }
I would look closer at Firefox, because I don't think Behat is the culprit here.
From what I can make out, what is happening is:
Behat tells Firefox to navigate to 'http://my-virutalhost.test/redirect/code1code2'
This URL responds with a HTTP redirect to 'http://some-page-here.com/'
Firefox honours the HTTP redirect but for some reason appends /login to the URL.
I would look into the responses that Firefox is getting to ensure that the correct redirect url is returned.
Is your redirect ok ? If your content page show the /login, then When I go to the url "/redirect/code1code2" must send to this page.
As you use the MinkExtension, did you tried with the default Step When I go to '/redirect/code1code2' ?
Or have you access to the page if you do directly When I go to the url 'http://some-page-here.com' ?
And for the http://some-page-here.com/login stuff, It's strange... If your page is able to show you the /login content, then it must say it has access to http://my-virutalhost.test/login

history.push in react router fires new request, nginx return 404

I read a lot of questions about 'history.push nginx react-router' but I didn't find the solution for the problem I'm facing.
The problem is, when I log in my application in my Login component I do something like this after the ajax call is executed:
cb = (res) => {
if (res.token!== null && res.token !== undefined){
localStorage.setItem("token",res.token);
localStorage.setItem("expiresIn",res.expiresIn);
localStorage.setItem("email", res.email);
**history.push('/home/0/0');**
}else{this.setState({errorTextMail:"wrong mail or wrong password!"})}}
Locally it works fine but in the console the history.push('/home/0/0') fires a request that nginx doesn't handle and return 404, but in my browser the app log me in and I don't see the error.
Instead when I build the app and put the build folder under nginx to serve static files, when I try to login it show me the 404 page. Then if I refresh the page (removing the /home/0/0 from the url) it works fine, recognize the token and log me in and I can browse other route of the app.
I was supposed that history.push would have been handled by react-router, just changing the component mapped by the appropriate <Route path="/home/:idOne/:idTwo" component={Home} /> component and not firing a new request to nginx.
My question is, there is a way to switch compoent when the cb function return my token instead of using history.push('/home/0/0')?
Note the history object is defined this way
import history from './history';
and the history.js's content is :
import createHistory from 'history/createBrowserHistory'
export default createHistory({
forceRefresh: true
})
Thanks for any suggestion.

Angular 2 Routes with .do extension

In my angular2 application i have two components (profile / projects) so my routes are like
{ path: 'profile', component: ProfileComponent },
{ path: 'projects', component: ProjectsComponent }
and i need to integrate angular 2 in existing struts application where all urls are having .do as url extension
so i have updated my routes to
{ path: 'profile.do', component: ProfileComponent },
{ path: 'projects.do', component: ProjectsComponent }
when i launch my application directly with localhost:3000/profile.do i am getting Cannot GET /profile.do error
where as when launch application using localhost:3000/ and click hyper link my profile it works
Any suggestion or solution to access my application with localhost:3000/profile.do url
When you hit localhost:3000/profile.do it goes directly to server and tries to resolve the resource, if appropriate redirects are not set on server side you will get errors saying resource not found, Angular routing kicks only after the default page is loaded, this is why it works when the page is already loaded and you hit hyperlink.
Set appropriate redirects on server side.
Hope this helps!!

Internal Server Error in OAuth for Google

EDIT: I was able to resolve the original error here when I realized my ROOT URL was set to my IP address rather than my domain. However, I now have a new issue. My client ID is the same as the original post below. This works fine in the local app, but in production, the popup flashes for a second and then the login box displays "Internal Server Error". I can't see any other messages that would explain it.
I am using the service-configuration package to load the settings, as follows:
ServiceConfiguration.configurations.upsert(
{ service: "google" },
{
$set: {
clientId: "************",
loginStyle: "popup",
secret: "***********"
}
}
);
If I add ?close to the end of my Authorized redirect URI, the Google popup comes up with a redirect_uri_mismatch error, showing the URI without ?close. I think there was an issue resolved here but it at least shows me that my project in Google is being recognized.
ORIGINAL POST
I am setting up an OAuth 2.0 client ID for accounts-google in Meteor and am seeing the following error:
400. That’s an error.
Error: invalid_request
Invalid parameter value for redirect_uri: Raw IP addresses not allowed:
http://***.***.***.***/_oauth/google
My Client ID in Google:
Authorized Javascript Origins
http://localhost:3000
http://myApp.com
Authorized redirect URIs
http://localhost:3000/_oauth/google
http://myApp.com/_oauth/google
I understand I must not be properly pointing the domain to the IP address. I have already set up an A record and the site works fine in other regards though, so not sure what step I missed.

Error Message: redirect_uri is not owned by the application

::UPDATE:: LINKS DO NOT EXIST ANYMORE!
Very strange indeed, this is definitely a bug! I did a test with app_id from another application and it worked.
See for yourself:
https://apps.megalopes.com/megabraziltv/test.php (app_id correct)
https://apps.megalopes.com/megabraziltv/test2.php (app_id from another application)
---/---
I found several people with the same question and all the answers are equal:
Site URL is not same as REQUEST_URI (Redirecting URL)
My app setting are:
Secure Page Tab URL: apps.megalopes.com/megabraziltv/...
App Domain: megalopes.com
code:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/pt_BR/all.js">
</script>
<script>
FB.init({
appId:'123456789', cookie:true,
status:true, xfbml:true
});
FB.ui({ method: 'apprequests',
message: 'Here is a new Requests dialog...'});
</script>
This simple code is not redirecting to any other url. I tested on the js console getting the same results. Sometimes works and sometimes I get this error message:
API Error Code: 191 API Error Description: The specified URL is not
owned by the application Error Message: redirect_uri is not owned by
the application.
Regardless of being page tab or canvas, you must identify the website Site URL in https://developers.facebook.com/apps
How I fixed:
App Domain: megalopes.com (domain)
Site URL: / Secure Canvas URL: / Secure Page Tab URL: https://www.megalopes.com (subdomain)
I think I have run into something similar before.
In the summary page of your app ensure both the Secure Canvas URL and Page Tab URL are populated.
The URL in my redirect_uri should have "http://" in the beginning. It was missing the protocol information, thus leading Facebook not to recognize my website and throw this annoying 191 error. I finally found out after one hour pulling the hair I (still) have left.
You have to create a channel page, which allows "cross domain communication in certain browsers"
This is an html page (saying /channel.html) on your server, which only contains :
<script src="//connect.facebook.net/en_US/all.js"></script>
And make the Javascript SDK aware of it :
FB.init({
appId: 'xxxxxx',
cookie: true,
channelUrl: location.protocol + '//' + location.host + '/channel.html'
});
More about this :
https://developers.facebook.com/docs/reference/javascript/FB.init/
https://developers.facebook.com/docs/reference/javascript/
It's because of domain URL that you mentioned in facebook's mistake. Domain URL wont be like www.site.com
Update your domain url like subdomain.site.com.
Now it surely work.

Resources