I'm using MySQL database in node.js application but can't connect with MySQL. I just changed the XAMPP server port 80 to 600, but what's the problem in MySQL connection?
Connection node.js code:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
port : '3306',
user : 'root',
password : '',
database :'appdb'
});
Request headers:
Request Headers
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Host localhost:1337
Referer http://localhost:1337/
User-Agent Mozilla/5.0 (Windows NT 6.2; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
X-Requested-With XMLHttpRequest
Throwing error message:
module.js:340 throw err; ^ Error: Cannot find module 'D:\project\hotel\app.js' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:902:3
You shouldn't use the port of your xamp server, but the port of your mysql server (usually 3306).
Related
I have a Fastapi running on localhost:8020 and I have access to documentation with:localhost:8020/docs and the openapi.json file is in localhost:8020/openapi.json.
I want to redirect localhost:8020/docs to localhost:8080/docs with nginx. Here is my nginx.conf:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
sendfile on;
upstream docss {
server 172.17.0.1:8020;
}
server {
client_max_body_size 500M;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
client_body_timeout 600;
listen 8080;
resolver 127.0.0.11;
autoindex off;
server_name localhost;
server_tokens off;
location /docs/ {
proxy_pass http://docss/docs;
}
}
}
with the above config, when I open localhost:8080/docs/, I receive this error:
Failed to load API definition. Errors Hide Fetch error Not Found
/openapi.json
and in the nginx docker log, I receive this error:
172.21.0.1 - - [23/Jun/2022:18:10:35 +0000] "GET /docs/ HTTP/1.1" 200 931 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"
2022/06/23 18:10:36 [error] 23#23: *1 open()
"/etc/nginx/html/openapi.json" failed (2: No such file or directory),
client: 172.21.0.1, server: localhost, request: "GET /openapi.json
HTTP/1.1", host: "localhost:8080", referrer:
"http://localhost:8080/docs/"
172.21.0.1 - - [23/Jun/2022:18:10:36 +0000] "GET /openapi.json HTTP/1.1" 404 548 "http://localhost:8080/docs/" "Mozilla/5.0 (Windows
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/102.0.0.0 Safari/537.36"
I guess it means that it couldnot find openapi.json at "/etc/nginx/html/openapi.json".
So my question is that how can I import 172.17.0.1:8020/openapi.json which is the upstream connection to "/etc/nginx/html/openapi.json".
This is the command I use to create nginx docker:
docker run --link ds-ai-ocr_web_1 --link ds-ai-ocr_api_1 --net ds-ai-ocr_default --name nginx -v c:/Users/ab/Documents/ds-nginx-conf:/etc/nginx -p 8080:8080 -d nginx
I guess I should mount openapi.json through this command but it doesn't work like this:
docker run --link ds-ai-ocr_web_1 --link ds-ai-ocr_api_1 --net ds-ai-ocr_default --name nginx -v c:/Users/amd/Documents/ds-nginx-conf:/etc/nginx -v http://172.17.0.1:8020/openapi.json:/etc/nginx/html -p 8080:8080 -d nginx
The requirement is to make a POST request to a particular URL with a given JSON payload. The URL will only respond if the payload is correct and the request is via POST.
This is my code:
request1 = HTTPRequest()
control = HTTPPluginControl.getConnectionDefaults()
httpUtilities = HTTPPluginControl.getHTTPUtilities()
control.setProxyServer("proxy.example.com", 1234)
payload = JSONObject({
"uaaURL": "https://com-example.something.com",
"sampleID": "admin",
"sampleSecret": "password",
"sampleID2": "example-sample-el",
"sampleSecret2": "ssenjsoemal/+11=",
"username": "test",
"someAttributes": {
"Groups": [
"example_com-abc"
],
"attribute": [
"value1"
]
}
})
payload = str(payload)
url = "https://example-something.com:6443/getvalues"
headers = [
NVPair('Content-Type', 'application/json'),
NVPair('Charset', 'UTF-8'),]
class TestRunner:
def __call__(self):
result = request1.POST(url, payload, headers)
print payload, headers
Now the issue with this is that my POST request gives me a 403 forbidden. However, when I use the same payload and send the request using DHC, it gives me a 200. So I'm sure of the payload and the link I'm connecting to. The proxy also I've tested in another script and works fine. Besides, if the proxy didn't work, I wouldn't get a 403 either.
Lastly, I'm parsing it as a string because POST requires the second argument to be string that it will internally convert into byte[].
I'm really not able to understand what's happening so any insight would be immensely helpful. Thanks in advance
EDIT: Fiddler's catch of DHC's Request
POST https://example-something.com:6443/getvalues HTTP/1.1
Host: example-something.com:6444
Connection: keep-alive
Content-Length: 688
Origin: chrome-extension://aejoelaoggembcahagimdiliamlcdmfm
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
{
"uaaURL": "https://com-example.something.com",
"sampleID": "admin",
"sampleSecret": "password",
"sampleID2": "example-sample-el",
"sampleSecret2": "ssenjsoemal/+11=",
"username": "test",
"someAttributes": {
"Groups": [
"example_com-abc"
],
"attribute": [
"value1"
]
}
}
I even edited my Grinder request headers to so
headers = (
NVPair('Content-Type', 'application/json'),
NVPair('Charset','UTF-8'),
NVPair('Accept', '*/*'),
NVPair('Accept-Encoding', 'gzip, deflate, br'),
NVPair('Accept-Language', 'en-US,en;q=0.8'),
NVPair('Connection', 'keep-alive'),
)
Best guess? You are likely missing a header with some credential information to pass a proxy/firewall/access gate to the application. Your REST Client, DHC, likely is passing this additional data but grinder is not. Grab a proxy (Fiddler, Charles, etc...) and check out the handshake from DHC to your destination and then match that with Grinder. My guess is you will find the delta.
The issue was that Grinder was not able to access the port. It had nothing to do with the JSON. The URL, which runs on port 6443 was the problem and Grinder couldn't access that (don't know why). I changed my URL itself to run on the default port 8080 and instantly my script worked. Thanks for the help!
I have runing bitcoind on ubuntu. bitcoin-cli works fine. I can not get working json rpc protocol
bitcoin.conf file:
testnet=0
rpcuser="bitcoinrpc"
rpcpassword="xxxxx"
rpcport=8332
rpcallowip="*"
server=1
http post request with url='http://bitcoinrpc:xxxxx#127.0.0.1:8332/' fails with 401 error.
request headers:
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,ru;q=0.6,de;q=0.4,sr;q=0.2
Authorization:Basic Yml0Y29pbnJwYzp4eHh4eA==
Cache-Control:no-cache
Connection:keep-alive
Content-Length:53
Content-Type:text/plain
DNT:1
Host:127.0.0.1:8332
Origin:chrome-extension://fhjcajmcbmldlhcimfajhfbgofnpcjmb
Pragma:no-cache
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/51.0.2704.79 Chrome/51.0.2704.79 Safari/537.36
request post payload:
{jsonrpc: "2.0", method: "getinfo", params: []}
What is correct way for bitcoind json rpc autentification?
For future googlers: a possible problem is that the password should not contain the pound sign (#) as this is treated as a comment!
I need to create a few nodes in neo4j and for that I am using json and curl inside my c++ program.
This is the request and response that I get back.
About to connect() to localhost port 7474 (#0)
Trying ::1...
Connection refused
Trying 127.0.0.1...
Connected to localhost (127.0.0.1) port 7474 (#0)
POST /db/data/cypher HTTP/1.1
Host: localhost:7474
Accept: */*
Content-Type: application/json
Content-Length: 4294967295
Expect: 100-continue
HTTP/1.1 100 Continue
{
"params" : {
"props" : {
"LocalAsNumber" : 0,
"NodeDescription" : "10TiMOS-B-4.0.R2 ",
"NodeId" : "10.227.28.95",
"NodeName" : "BLR_WAO_SARF7"
}
},
"query" : "CREATE (n:Router { props }) RETRUN n"
}
HTTP/1.1 500 Server Error
Content-Type: text/html; charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 0
Server: Jetty(9.0.5.v20130815)
HTTP error before end of send, stop sending
Closing connection 0
I am always getting this "500 Server Error". Is something wrong with the query?
Look at your query:
"CREATE (n:Router { props }) RETRUN n"
It should be RETURN:
"CREATE (n:Router { props }) RETURN n"
I have one api server backed with Zend Framework 2 with ZfrCors module to enable Cross-Origin Resource Sharing.
The server side zfrcors config::
<?php
/**
* This is the config file for ZfrCors. Just drop this file into your config/autoload folder (don't
* forget to remove the .dist extension from the file), and configure it as you want
*/
return array(
'zfr_cors' => array(
/**
* Set the list of allowed origins domain with protocol.
*/
'allowed_origins' => array('http://client.server'),
/**
* Set the list of HTTP verbs.
*/
'allowed_methods' => array('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'),
/**
* Set the list of headers. This is returned in the preflight request to indicate
* which HTTP headers can be used when making the actual request
*/
'allowed_headers' => array('Authorization', 'Access-Control-Allow-Origin', 'content-Type', 'application/x-www-form-urlencoded', 'application/json', 'text/javascript', 'text/html'),
/**
* Set the max age of the preflight request in seconds. A non-zero max age means
* that the preflight will be cached during this amount of time
*/
'max_age' => 3600,
/**
* Set the list of exposed headers. This is a whitelist that authorize the browser
* to access to some headers using the getResponseHeader() JavaScript method. Please
* note that this feature is buggy and some browsers do not implement it correctly
*/
// 'exposed_headers' => array(),
/**
* Standard CORS requests do not send or set any cookies by default. For this to work,
* the client must set the XMLHttpRequest's "withCredentials" property to "true". For
* this to work, you must set this option to true so that the server can serve
* the proper response header.
*/
'allowed_credentials' => true,
),
);
While on login in the client side(My client side application is ember.js), it sends request to the api.server domain (localhost) . But in firefox after preflight request nothing happens. It just gives me 200 OK status message and sits there. However if I run the client application in Chrome, it does gets passed from preflight stage to actual request that was made.
This is my Firefox inspect element result while sending a post credentials to another domain :
Access-Control-Allow-Cred... true
Access-Control-Allow-Head... Authorization, Access-Control-Allow-Origin, Content-Type, application/x-www-form-urlencoded
Access-Control-Allow-Meth... GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Orig... http://client.server
Access-Control-Max-Age 0
Connection Keep-Alive
Content-Encoding gzip
Content-Length 20
Content-Type text/html
Date Tue, 04 Mar 2014 08:38:29 GMT
Keep-Alive timeout=5, max=100
Server Apache/2.2.22 (Ubuntu)
Vary Accept-Encoding
X-Powered-By PHP/5.4.9-4ubuntu2.4
Request Headersview source
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Access-Control-Request-He... content-type
Access-Control-Request-Me... POST
Cache-Control no-cache
Connection keep-alive
DNT 1
Host api.server
Origin http://client.server
Pragma no-cache
User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0
The same request done in Chrome:
Preflight Stage:
Request URL:http://api.server/login
Request Method:OPTIONS
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:api.server
Origin:http://client.server
Referer:http://client.server/signin
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36
Response Headersview source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Authorization, Access-Control-Allow-Origin, Content-Type, application/x-www-form-urlencoded
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin:http://client.server
Access-Control-Max-Age:0
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:20
Content-Type:text/html
Date:Mon, 03 Mar 2014 07:18:41 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.2.22 (Ubuntu)
Vary:Accept-Encoding
X-Powered-By:PHP/5.4.9-4ubuntu2.4
The actual post request Headers:
Request URL:http://api.server/login
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:55
Content-Type:application/json; charset=UTF-8
Host:54.254.23.183
Origin:http://client.server
Referer:http://client.server/signin
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36
Request Payloadview source
{identity:pbehera, password:123, remember:true}
identity: "pbehera"
password: "123"
remember: true
Response Headersview source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://client.server
Access-Control-Expose-Headers:
Connection:Keep-Alive
Content-Length:31
Content-Type:application/json; charset=utf-8
Date:Mon, 03 Mar 2014 07:18:42 GMT
Keep-Alive:timeout=5, max=99
Server:Apache/2.2.22 (Ubuntu)
Vary:Origin
X-Powered-By:PHP/5.4.9-4ubuntu2.4
What I am doing wrong ? Also same case with Opera as Firefox.
The header field Access-Control-Allow-Origin: differs between Firefox and Chrome. The URL specified by this field must match the domain (host + port) of the page that the javascript is running on, since you specified that you are sending credentials. This is probably not the case for the Firefox request for some reason.