Ionic - XMLHttpRequest cannot load - .htaccess

I have an Ionic PWA, so it runs in browser. I'm trying to send requests to my symfony backend. At first I had everything installed on my local pc and the requests were working with an ionic proxy. Now I have installed both applications on a server. At first I have tried to use the url from the backend without proxy. Then there was a CORS error. Then I wrote a .htaccess file for the backend with the following input:
Header add Access-Control-Allow-Origin "\*"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
Now I'm getting this:
XMLHttpRequest cannot load
... Response for preflight
has invalid HTTP status code 405
If I set a proxy as before on the local installation like this:
"proxies": [
{
"path": "/api",
"proxyUrl": "http://api.example.com/api"
}
]
I'm getting a 404 not found error, when I try to send a request to http://app.example.com/api
Can someone tell me how it will work correctly when frontend and backend are on a server and the app runs in the browser?

If you're getting a 405 back, that's a method not supported error, so it looks like you server isn't configured to handle OPTIONS requests. That's causing the pre-flight CORS request to get rejected.

Related

Get error 503 on node js server on shared host

Get error 503 from post ajax request on node js express on shared host but work fine on local server
i try checking the url call on the ajax request

Frappe Framework ERPNEXT: How to enable CORS on localhost

I am trying to develop a React Client that consumes the Frappe REST API but on each request I am getting a CORS error. according to the community forum, I have to edit the Nginx conf to allow CORS requests but I am facing this error on my machine (localhost) and the dev server is not Nginx so how can I allow CORS requests on localhost?
// site_config.json
{
// allow all origins
"allow_cors": "*"
// restrict to Origin:
"allow_cors": ["http://demo-site.com"]
}
Reference:
https://github.dev/frappe/frappe/blob/07af98255b6ac9bb3b277fc1b9d6999a86a90e9f/frappe/app.py#L159
I don't think you need to configure CORS, especially during local development.
Let's say your React client is running the port 8080 and Frappe server is on 8000. You can proxy all your requests from localhost:8080 to localhost:8000.
In production, you can generate the static assets and put them in the www folder of the Frappe app.
Add "allow_cors": "*" to common_site_config.json and restart bench

Proxy error: Could not proxy request /api/register from localhost:3000 to http://localhost:8000/ (ECONNREFUSED)

I have a React frontend that uses jwt to authenticate with the laravel backend. The backend works and is connecting just fine using laravel views, but when I try to proxy a request from React, it gives me a Connection Refused error.
Proxy error: Could not proxy request /api/register from localhost:3000
to http://localhost:8000/ (ECONNREFUSED).
Connecting to http://localhost:8000/api/register works normally. And sending a POST request with Axios also works normally and returns the token json. But when I proxy it with node, it doesn't work.
in my package.json code is
"proxy": "http://localhost:8000",
Please anyone help me. how to fixed it?
I think you should add "/" after the port number in package.json file
"proxy": "http://localhost:8000/"
Please check these points and solve your problem:
Please check your ip of backend server.(https://127.0.0.1:3000 or http://127.0.0.1:3000)
Please check your backend server is running or stop if stopped then start ypur server.
Please check protocol http or https used in your backend server.(https or http)
I hope with the help of these points you can solved your problem which is facing by you.
You need to run both of the local host (3000 and 8000) in different terminal. For example, run the backend server in os(windows's) command prompt cmd and frontend server in vscode terminal.

Node.js socket hang up when agent is present

I have the following setup:
Client => Proxy server => Origin Server
I'm using the following Node.js libraries for each of these pieces, respectively:
isomorphic-fetch => http-proxy => http
Here's a gist of the setup in two files, one for each of the servers and one for the client: https://gist.github.com/headquarters/850cbb199ff397c6da56fb8d86113a7e
To run this locally, run node server.js in one shell and node fetch.js in another shell.
With the servers running, if I go to http://localhost:8818 in a browser, I get the sample response {"a":"b"}, so that's working. If I go to http://localhost:9818, I also get that response, so the proxying appears to be working fine. However, if I run DEBUG=* node fetch.js, which includes the HTTP proxy agent, the request fails (see output at https://gist.github.com/headquarters/850cbb199ff397c6da56fb8d86113a7e#file-failure-txt).
Without the agent property, the fetch command works fine on the command line. How do I go about debugging this socket hang up error?
Turns out I didn't read the https-proxy-agent docs closely enough. This line was a bit confusing: An HTTP(s) proxy http.Agent implementation for HTTPS--the PROXY itself can be either HTTP or HTTPS, but the origin server has to be HTTPS for this flavor of proxy-agent. For an HTTP origin server, I had to use http-proxy-agent. Thus, the socket hang up was probably coming from https.Agent trying to access an HTTP endpoint. It worked when I switched to http-proxy-agent.

Get error when i try to test Multi-Room Chat Application sample code

i found this sample code from github as chat-nodejs named and i want to test it how is it work, after installing socket.io and expressjs and running server and click to connect to server i get this error on firebug:
GET https://apis.google.com/_/scs/apps-static/_/js/k=...TcCOZ5yY8jtGvNKVwrKHFFcvb9eCe_w/cb=gapi.loaded_1
GET http://localhost/socket.io/?EIO=3&transport=polling&t=LbtPp7S
"NetworkError:404 Not Found -
http://localhost/socket.io/?EIO=3&transport=polling&t=LbtPp7S"?EIO=3&...LbtPp7S
Cross-Origin Request Blocked:
The Same Origin Policy disallows reading the remote resource at
http://localhost/socket.io/?EIO=3&transport=polling&t=LbtPp7S.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
You're getting a NetworkError:404 Not Found because the serverAddress in Line 15 of chat.io.js doesn't have the server port 8080 in it. Add port number to it.
serverAddress = 'http://localhost:8080',
Additionally, socket.io might not work well if the client and server installation of it, are of different version.
index.html doesn't use a local one. The recent version of socket.io dint work for this repo. I had to install 0.9.13 on the server side for it to work.

Resources