Provisional headers are shown socket io - express

I am trying to set up socket io for the first time in a production env. I think I am running into some CORS related issues.
Currently the error I am getting is
Provisional headers are shown
Server side code:
app.js
app.io.attach(server);
index.js
app.io = require('socket.io')({origins: allowed_header});
On client side:
const socket = io(process.env.SOCKET_ADDRESS);
where socket address is http://localhost:8080 for dev, and https://websiteName.com:8080 for production
The server uses nginx's default port. The app works fine when running locally, but it logs in above error in production env.
Thanks
UPDATE:
I tried to change my local client to connect to remote server. And it works this way as well. It is just my production client now have the following issue:
Failed to load resource: the server responded with a status of 403 (Forbidden)
UPDATE2:
I could not really solve the problem, so instead I just did the following:
origins: ['http://localhost:3000', 'http://localhost:4000', '*:*']
And it works for now, but I'd like to figure out what is going on. I tried to replace : with https://example.com:80, and this didn't work.

Hope this will help with all the CORS error
const cors = require('cors');
app.use(cors());
Docs CORS

Related

Nuxt/Axios: baseURL with same origin, but different port possible?

Short:
How can I set a different port for axios request in nuxt.config, but with same origin domain?
Long:
On my production side I have an express server that delivers my frontend and backend over the same port (e.g. http://192.168.2.22:8800). Axios will make API requests on that same origin with same port. Works very well.
On my dev side I have an express server that delivers only my APIs and I also have the nuxt server, serving the frontend. Both running on different ports (e.g. http://192.168.2.22:8800 for my backend and http://192.168.2.22:3000 for my nuxt). So that I can also execute the API calls in my development environment, I set the baseURL in my nuxt.config to http://localhost:8800.
My problem here is, I can only test my dev environment if I'm on localhost. If I want to access via another pc, the api calls are also started on localhost, which is not reachable.
Is there a way to add a dynamic port to the baseURL?
My nuxt.config right now:
axios: {
baseURL: isDev ? 'http://localhost:8800/api/v1' : '/api/v1'
},
For a better overview.
This is what I want on my production (only express is running):
Frontend: http://192.168.2.22:8800
Backend: http://192.168.2.22:8800
This is what I want on my dev side (two servers are running - express and nuxt):
Frontend: http://192.168.2.22:3000
Backend: http://192.168.2.22:8800
Environment variable are still your best bet here indeed. It will help you configure each environment to your liking and will avoid a lot of mistakes too.
Here is an interesting article on the subject too: https://nuxtjs.org/blog/moving-from-nuxtjs-dotenv-to-runtime-config

Access Vue.js application from other device in the same network (also using proxy)

so my problem is basically the same as here, but the question isn't answered yet.
The problem ist, that I can't view my vue application in the webbrowser when visiting <pc_ip>:8080. However when starting my vue.js app with npm run serve it tells me, that this is how I could access the page besides doing localhost:8080. It works from my PC but with my phone which is connected to the same wifi I get the error that the url is not reachable.
Thanks in advance!
UPDATE:
So after finding some other posts I also tried writing some stuff to a vue.config.js like here, here, here or here e.g.
module.exports = {
devServer: {
port: 8080,
host: '0.0.0.0'
}
}
However the problem still persists. I also tried replacing the host in that file with my actual ip, but it does not work either.
UPDATE 2:
As mentioned in a comment, I had a similar problem some time ago, when trying to access my flask server from my phone which was in the same network. Back then I set the host variable to the pc's IP and it worked. As I tested again just now, I realized that the corporation proxy I have to use in parallel could play a role in this. When I wasn't connected via using plink.exe, I could not access my running flask server from my phone. When I connected after that, everything is working.
Could the proxy or a missing configuration be hindering me to access my vue application?
UPDATE 3: so i turned of my firewall completely and then i could access the page from another device. I wondered if some other rule was blocking the port like in this post Windows Firewall - Laravel Artisan Serve - Allow Port in Inbound Rule (not working). But I am not sure how I would find that rule if there is one blocking my port?
Please follow this link:
Work around this problem
I add the following code to my vue.config.js
module.exports = {
devServer: {
port: 80,
host: '0.0.0.0'
}
}
change the port number according to your need.
Normally when you execute the npm run serve command, it gives you two addresses to access your application. A local address and a network address. Like this :
App running at:
- Local: http: // localhost: 8080 /
- Network: http://IP_ADDRESSE:8080/
So with your phone you should use the network address and not the local one.

Spartacus - Error occurred while trying to proxy request

when doing yarn start in spartacus application at localhost , I am getting following error:
[HPM] Error occurred while trying to proxy request /rest/v2/electronics-spa/cms/pages?fields=DEFAULT&pageType=ContentPage&pageLabelOrId=homepage&lang=en&curr=USD from localhost:4200 to https://localhost:
9002 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
I have pretty standard proxy.bankend.js file. Any suggestions what i can investigate ?
I already tested backend is reachable via url directly.
Regards,
Archit
I am familiar with this situation. Usualy this error happens when the endpoint I an trying to proxy to is not reachable.
Looking at the error I can see your request is still going to https://localhost:9002 so I believe it's possible your proxy might not be picked up.
You should make sure that you specified the proxy config correctly. It can be done in your package.json by modifying the start script: "start": " ng serve --proxy-config proxy/proxy.backend.js", (in this case my proxy is in a proxy folder).
Hope this helps!

Developing using Netlify Dev with Vue JS and Netlify Functions

I am using vue + netlify for a small web app that uses netlify functions I built. Everything works fine in production (when I commit to master and netlify auto-deploys based on my master branch) but when I try to use netlify dev to spin up a local development instance, calls to the netlify function are failing:
VM23:1 POST http://localhost:18002/.netlify/functions/customfunction 404 (Not Found)
Clearly the endpoint in the dev enironment is not the same, but how do I know what that endpoint may be? In the console when running the netlify dev command it says that the lambda server is listening on 3467... but trying to use endpoint http://localhost:34567/.netlify/functions/customfunction results in a CORS error. Any help here would be appreciated!
you might be getting the CORS error because your server is not running on the same host with your vue app and to fix this you have to set a proxy and for that you need to create a vue.config.js file on the project directory (not the vue folder) then past the following code:
module.exports = {
devServer: {
proxy: 'http://localhost:34567' // the port your server in running on
}
}
now your proxy is set so your request URL will the following :
/.netlify/functions/customfunction
Doc reference : https://cli.vuejs.org/config/#devserver-proxy

CORS issues with vue/node to rack/thin via nginx

I had this working properly and all of a sudden during a restart stopped working and I can't get to the bottom of what happened.
Basically, vue/node (dev) mode is using http but the ajax uses https to the server.
Server responds with all headers including Access-Control-Request-Origin and I can see json data response from the server in the firefox dev tools
But for some reason it throws an Error: Network Error alert. Inspecting in dev tools I find
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://r.roller.lan/workstations?session_token=2de63puojmt3ubkfp94c3ohm45. (Reason: CORS header “Access-Control-Allow-Origin” does not match “https://devv.roller.lan:8080”)
I am making request from http://devv.roller.lan:8080 and somewhere in the chain gets translated to https:// which doesn't match?
Thanks
Everything works as expected after I added highlighted portion from the Nginx Reverse Proxy article Koshux referenced to the nginx conf.