I'm working on creating a basic ReactJS Frontend App that has to send data to an API created with php. My react app is hosted on localhost:3000 using XAMPP and the php file is hosted on localhost:8000. when I try to connect to it I get a connection refused error. I use Axios to send a Post request.
I know this might be very general but any ideas to how to solve this. or go about programming that App?
This is what it currently is. I get a net::ERR_CONNECTION_REFUSED whenever I call it
axios.post('http://localhost:8000/file.php', someData)
Although I'm not sure there's a config option in Axios to specify port, you should be able to send a post request to that port like this:
axois.post('http://localhost:8000')
.then((success) => {
console.log(success)
})
You may need to add a proxy in your package.json file:
"proxy": "http://localhost:8000"
Read more: https://docs.npmjs.com/misc/config#proxy
Related
I am working on an authentication (login & registration) application using java (android).
Now in order to communicate with a database I was requested to implement it using Laravel web app. I configured everything (Laravel passport) and tested it using postman.
I deployed the website on Heroku and configured pgsql with it. then I duplicated the request in postman and changed the URL.
the problem is that it is adding the new user in the database but it is returning 500 internal server error with no access token
postman response when adding the user:
the new user in the db:
the code responsible for adding users (same code is still working on localhost)
You probably have an error after creating the user. You receive a server-side 500 response because it is not sending you the correct headers to respond in json.
Some APIs require you to send particular headers along with requests, typically to provide additional metadata about the operation you are performing. You can set these up in the Headers tab. Enter any key-value pairs you need and Postman will send them along with your request. As you type, Postman will prompt you with common options you can use to autocomplete your setup, such as Accept
Make sure you are sending Accept: application/json and in your .env file this APP_DEBUG=true to see the error.
I have build an app with vue (not with vue cli). I ran It on my local host. What I am trying to do is to add php in this Project. But I cannot run php and vue on the same local host together. Is there a way to solve this problem ?
I know when the app is created with command line interface you can compile them with webpack. But how to combine back-end and front-end together when the app is created with vue?
Thanks a lot in advance
Vue is a javascript framework and I suppose you are familiar with javascript. In javascript, we use AJAX to interact with PHP. we used to send POST and GET request to the server via ajax and javascript and we get the response from the server.
In a similar way, you need to learn how to create Rest API for GET and POST via vueJS and PHP.
You Need to create Rest API for VueJS and PHP. There is no other solution. follow the links below as per your need.
Here is the Github Link for the Same
You can also use Laravel framework with Vue
I have PHP application in Symfony 2.8 and its all REST API in ec2
Frontend is hosted in separate EC2. I am using ELB.
Now I want that only my reactjs front should be able to call API endpoint and if other try via curl or postman then it should not work.
Also I want to have some part like /public to open to public so that anyone can access that.
I am not sure if its possible to do at Symfony level or secuirty groups or NACL or ALB level.
Any ideas?
First of all you can just implement authentication and you reactjs app will only that can access this with the right credentials.
Or you can maybe verify the user-agent. You can create a specific user-agent for your react js app and check it in your endpoint.
I have been trying to built Chat application in my website. I have using slim php as my API for normal HTTP request for forms and results. since, i need to implement user chat. so I have implemented web-socket using ratchet library that works perfectly. But the problem is I don't how to globalize the session storage for both http server and websocket server as I am using slim framework. Any help or guide please.
Thanks
I'm developing a Hybrid App where I use ajax requests to connect to a remote database. The database is accessed through the Laravel(5) framework. When I send requests to the remote laravel web app, I get the following case.
Error with message, No Access Control Allow Origin Header Present.
To solve this problem I added the access control headers to the index.php at public/ directory. Then the above error no longer occurs(Yes, I know that we can do the same using a Middleware and it is the recommended way). But then an internal server error occurs saying csrf Token mismatch exception. I know that if this was a web appilication, we could have easily added the csrf_token. Since this is a hybrid app, I cant set a token since I can't run any PHP here and I can't obtain a token by an ajax request.
Up to now, I have read almost every thread related to this in Laravel Forums. But there were no feasible answer. Does anyone have an idea about how to solve this issue?
Thanks in Advance!