Woocommerce product api v3 not accept urls images for 9191 port. Only 8080 - api

My POST request (JSON to create PRODUCT IN WOOCOMMERCE API V3) fail for images.
I have the same image exposed to the internet through 2 different ports. https fails too
---------------- Fail: not Works for 9191 or other port --------------------------------
{
"src": "http://190.64.76.10:9191/img/logo.png"
}
Error
{
"code": "woocommerce_product_image_upload_error",
"message": "Error getting remote image http://190.64.76.10:9191/img/logo.png. A valid URL has not been provided",
"data": {
"status": 400
}
}
---------------- Works fine with 8080 port --------------------------------
{
"src": "http://190.64.76.10:8080/img/logo.png"
}
Any ideas ?????

Internally, the URL is validated by calling wp_http_validate_url. Among other rules, it checks whether the port is one of 80, 443 or 8080:
$port = $parsed_url['port'];
if ( 80 === $port || 443 === $port || 8080 === $port ) {
return $url;
}
You can see the relevant part of the code on GitHub here. There is also an issue where some had the same problem, which you can find here.
So, bottom line, by default you just cannot use any other port than 80, 443 or 8080. There is no way to change that other than disabling the URL validation in WordPress, which is probably not a good idea security-wise.
But if you really need it, you can do it by adding the following code in a plugin or theme in your WordPress installation:
add_filter('http_request_args', function ($args, $url) {
$args['reject_unsafe_urls'] = false;
return $args;
}, 50, 2);

Related

API Call works for IPv4 Address (127.0.0.1) but get a "Error: connect ECONNREFUSED ::1:3001" when using localhost

So I have a very simple API call using fetch on my frontend to http://localhost:3001/test that gives me an error: Error: connect ECONNREFUSED ::1:3001
However, when I call that API directly (enter the api uri directly into my browser), it works just fine. Also when I change localhost to http://127.0.0.1:3001/test on my frontend fetch call, that works too.
This seems like it's gotta be a network error since ::1 and 127.0.0.1 resolve to the same address but one is IPv4 and the other is IPv6 right? Anyone have any thoughts on why this could be?
frontend fetch (BACKEND_URL = http://localhost:3001):
export async function getStaticProps() {
const res = await fetch(`${BACKEND_URL}/explore`, {
method: 'GET',
headers: {
"Content-Type": 'application/json',
Origin: BASE_URL,
},
});
...
}
Backend Server listening on port 3001 (PORT = 3001):
const PORT = process.env.PORT;
app.listen(PORT, '0.0.0.0', () => {
console.log(`Server is running on port ${PORT}`);
});
Stack: NextJS frontend, ExpressJS backend, MongoDB Atlas DB, NextAuth for auth
A couple of things can be the issue:
You need to enclose the IPv6 address between brackets, like http://[::1]:3001/test
The service is only listening on the IPv4 address and not on the IPv6 address. Depending on the server you may need to configure the listening address differently
Your post doesn’t contain enough information to go into more detail. Please edit your post to include the actual code, service and configuration so we can help you further.
When you use "localhost" in the backend URL, that is by default going to be resolved to the IPv6 address ::1. However, looking at the backend server code, that backend is listening on 0.0.0.0 which is IPv4.
You need to make that backend listen on IPv6:
const PORT = process.env.PORT;
app.listen(PORT, '::', () => {
console.log(`Server is running on port ${PORT}`);
});

Vue 2 devServer proxying does not work for websocket

I have simple web server in python running for example on 127.0.0.1:8080.
I can serve http-requests and web sockets.
This is example of server routes.
...
web.route('*', '/ws', ws_handler),
web.route('*', '/api/some_url', http_handler)
...
And I have frontend part of my application in Vue 2 JS.
I set up vue.config.js file for proxying dev server.
const host = "127.0.0.1"
const port = 8080
devServer: {
proxy: {
"/api": {
target:`http://${host}:${port}/`,
secure:false
},
"/ws": {
target:`ws://${host}:${port}/`,
ws:true,
secure:false,
changeOrigin:true
}
}
}
When I make http requests, for example
let res = await axios.get('/api/some_url');
everything works fine, but if I want to set up websocket connection
soc = new WebSocket('/ws');
I got error
Failed to construct 'WebSocket': The URL '/ws' is invalid.
For websockets my settings does not work.
Connection sets up and everything works fine if full address is provided.
soc = new WebSocket('ws://127.0.0.1:8080/ws');
I have read many articles and had no success for resolve my issue - how can I do proxying websocket connection for Vue JS dev server.
You should instantiate your WebSocket as ws = new WebSocket('ws://' + window.location.host + '/ws');

How to expose RSK node to an external network?

I am having problems exposing my RSK node to an external IP.
My startup command looks as follows:
java \
-cp $HOME/Downloads/rskj-core-3.0.1-IRIS-all.jar \
-Drsk.conf.file=/root/bitcoind-lnd/rsk/rsk.conf \
-Drpc.providers.web.cors=* \
-Drpc.providers.web.ws.enabled=true \
co.rsk.Start \
--regtest
This is my rsk.conf:
rpc {
providers {
web {
cors: "*",
http {
enabled = true
bind_address = "0.0.0.0"
hosts = ["localhost", "0.0.0.0"]
port: 4444
}
}
}
}
API is accessible from localhost, but from external network I get error 400. How do I expose it to external network?
You should add your external IP to hosts. Adding just 0.0.0.0 is not enough to indicate all IPs to be valid. Port forwarding needs to be enabled for the port number that you have configured in rsk.conf, which in this case is the default value of 4444.
rpc {
providers {
web {
cors: “*”,
http {
enabled = true
bind_address = “0.0.0.0"
hosts = [“localhost”, “0.0.0.0", “216.58.208.100”]
port: 4444
}
}
}
}
where 216.58.208.100 is your external IP

How to serve data for AJAX calls in a Vue.js-CLI project?

I have a Vue.js CLI project working.
It accesses data via AJAX from localhost port 8080 served by Apache.
After I build the project and copy it to a folder served by Apache, it works fine and can access data via AJAX on that server.
However, during development, since the Vue.js CLI website is being served by Node.js which is serving on a different port (8081), I get a cross-site scripting error) and want to avoid cross-site scripting in general.
What is a way that I could emulate the data being provided, e.g. some kind of server script within the Vue.js-CLI project that would serve mock data on port 8081 for the AJAX calls during the development process, and thus avoid all cross-site scripting issues?
Addendum
In my config/index.js file, I added a proxyTable:
dev: {
env: require("./dev.env"),
port: 8081,
autoOpenBrowser: true,
assetsSubDirectory: "static",
assetsPublicPath: "/",
proxyTable: {
"/api": {
target: "http://localhost/data.php",
changeOrigin: true
}
},
And now I make my AJAX call like this:
axios({
method: 'post',
url: '/api',
data: {
smartTaskIdCode: 'activityReport',
yearMonth: '2017-09',
pathRewrite: {
"^/api": ""
}
}
But now I see in my JavaScript console:
Error: Request failed with status code 404
Addendum 2
Apparent axios has a problem with rerouting, so I tried it with vue-resource but this code is showing an error:
var data = {
smartTaskIdCode: 'pageActivityByMonth',
yearMonth: '2017-09'
}
this.$http.post('/api', data).then(response => {
this.pageStatus = 'displaying';
this.activity = response.data['activity'];
console.log(this.activity);
}, response => {
this.pageStatus = 'displaying';
console.log('there was an error');
});
The webpack template has its own documentation, and it has a chapter about API proxying during development:
http://vuejs-templates.github.io/webpack/proxy.html
If you use that, it means that you will request your data from the node server during development (and the node server will proxy< the request to your real backend), and the real backend directly in production, so you will have to use different hostnames in each environment.
For that, you can define an env variable in /config/dev.env.js & /config.prod.env.js

Configuring Varnish on cPanel with multiple IP addresses

So I am trying to configure Varnish on my cPanel server which has a primary shared IP along with a few other secondary IP addresses for dedicated domains that are hosted with me.
I have followed the following guide on how to get varnish to run, and it works perfectly for the shared IP domains, but the secondary IP domains won't load at all, going to the default Apache page.
http://crybit.com/how-to-enable-varnish-in-cpanel-server/
I was looking online for other resources and found to configure multiple hosts in the default.vcl file for varnish, so I had done exactly that but the service fails to load as soon as I try launch it, even with just two hosts in the file.
Am I doing something wrong?
backend default {
.host = "11.11.11.11";
.port = "8080";
}
backend secondary1 {
.host = "22.22.22.22";
.port = "8080";
}
I have also tried configuring the following below but also to no success, service won't load!
sub vcl_recv{
if(req.http.host == "www.secondary1.com") || (req.http.host == "secondary1.com) {
set req.backend = secondary1;
} else {
set req.backend = default;
}
}
Hoping that someone can give me a hand!
Can you please check your /etc/sysconfig/varnish file and change your -a flag with your IP's.
-a 192.168.0.1:80,192.168.0.2:80 \