Keeping getting server and network error when trying to retrieve data from my LoopBack api - node.js

When I open my loopback API in Firefox try and use the GET commands for the controllers on my user and plant collection from my mongodb
I get this response from the Curl
curl -X 'GET' \
'http://[::1]:3000/users?filter=%7B%0A%20%20%22offset%22%3A%200%2C%0A%20%20%22limit%22%3A%20100%2C%0A%20%20%22skip%22%3A%200%2C%0A%20%20%22order%22%3A%20%22string%22%2C%0A%20%20%22where%22%3A%20%7B%0A%20%20%20%20%22additionalProp1%22%3A%20%7B%7D%0A%20%20%7D%2C%0A%20%20%22fields%22%3A%20%7B%0A%20%20%20%20%22userID%22%3A%20true%2C%0A%20%20%20%20%22email%22%3A%20true%2C%0A%20%20%20%20%22phoneNumber%22%3A%20true%2C%0A%20%20%20%20%22plantsRegistered%22%3A%20true%0A%20%20%7D%0A%7D' \
-H 'accept: application/json'
And this response from the Request URL
http://[::1]:3000/users?filter=%7B%0A%20%20%22offset%22%3A%200%2C%0A%20%20%22limit%22%3A%20100%2C%0A%20%20%22skip%22%3A%200%2C%0A%20%20%22order%22%3A%20%22string%22%2C%0A%20%20%22where%22%3A%20%7B%0A%20%20%20%20%22additionalProp1%22%3A%20%7B%7D%0A%20%20%7D%2C%0A%20%20%22fields%22%3A%20%7B%0A%20%20%20%20%22userID%22%3A%20true%2C%0A%20%20%20%20%22email%22%3A%20true%2C%0A%20%20%20%20%22phoneNumber%22%3A%20true%2C%0A%20%20%20%20%22plantsRegistered%22%3A%20true%0A%20%20%7D%0A%7D
And I get this message when I open up the firefox inspector
Source map error: Error: NetworkError when attempting to fetch resource.
Resource URL: http://[::1]:3000/explorer/swagger-ui.css
Source Map URL: swagger-ui.css.map
Within the server response it appears as
TypeError: NetworkError when attempting to fetch resource.
I also got a server error(
Error: Internal Server Error) with the response body(I tried opening the API on chrome and got this error. I got this error on Firefox as well
{
"error": {
"statusCode": 500,
"message": "Internal Server Error"
}
}
I am not sure how to fix this so I'm hoping I could find a potential solution on here

Related

Vercel deployment, enviormental variables

Hey guys im trying to deploy my website and I keep getting stuck on these issues vercel build then vercel deploy -- prebuilt I get the error message of Error: ENOENT: no such file or directory, stat '/vercel/path0/.vercel/output/functions/_next/data/f3doRdmrRJC9QWLs2rG4w/index.json.func'
But when I run vercel deploy depending on my environmental variables for NEXT_PUBLIC_BASE_URL if I put http://portfolio-build-lem0bum28-bchang0999.vercel.app as my value the result i get is Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error FetchError: invalid json response body at https://vercel.com/login?next=%2Fdeployments%2Fportfolio-build-lem0bum28-bchang0999.vercel.app%3Fhost%3Dportfolio-build-lem0bum28-bchang0999.vercel.app%26redirect%3D1%26section%3D reason: Unexpected token < in JSON at position 0
if i put the NEXT_PUBLIC_BASE_URL with a value of http://localhost:3000 the error code I get is FetchError: request to http://localhost:3000/api/getPageInfo failed, reason: connect ECONNREFUSED 127.0.0.1:3000
any help to resolve this so I can deploy and move on from this project would be nice
http://portfolio-build-lem0bum28-bchang0999.vercel.app errorlocalhost:3000 error

Sever returning 400 when body passed with GET

I have an Express GET route to fetch all users. Whenever a req.body is present, the server is always responding with 400.
Obviously, I have body-parser and this behaviour is only experienced in the production k8s environment (working fine in localhost)
Is there any limitation to send req.body to GET routes? Express documentation doesn't say so
You need to set the content type --header "Content-Type: application/json" in the GET request and it should work.
curl --header "Content-Type: application/json" --request GET --data '{"username":"xyz","password":"xyz"}' https://example.com/posttest
and here is the nodejs snippet
app.get('/posttest', function(req, res){
console.log("posttest call received")
res.send(req.body);
});

digest auth with file upload in electron (superagent, urllib)

I have an Electron based application and it can discover certain onvif based devices. For a certain upload endpoint, the authentication is done with digest.
There are two processes running with this electron: node and chromium.
In the chromium process, I have urllib trying to do the digest authentication.
return new Promise((resolve, reject) => {
urllib.request(uploadUrl, {
method: 'POST',
files: {
filename: fs.readFileSync(filePath)
},
digestAuth: `${device.username}:${device.password}`
}).then((response) => {
log.info('apk uploaded', response)
return resolve(response.status)
}).catch((error) => {
log.info('error uploading apk', error)
})
})
This always returns:
Error: read ECONNRESET at TCP.onStreamRead (internal/stream_base_commons.js:209:20)
However, I also tried it with curl and it works perfectly with that
curl -v http://upload.url.62.62/upload \
--digest \
-u "username:passsword" \
--form filename=#"app.apk"
I thought it might be the Chromium process that makes things worse with digest. So I tried to do it in the main process with ipcHandler and it's the same error.
I'm not sure how can I translate this curl command into a node code.
I've tried superagent, urllib, axios-digest (using in node main process).
Superagent gives a different error
Error: Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.
axios-digest gives the error: reply was never sent
At this point I'm clueless on how to make this work.

RPC Error - valid string HTTPs rpc in Metamask

In my project, I tried to connect with metamask on Ganache. But I got the error like the following.
inpage.js:1 MetaMask - RPC Error: Expected an array with at least one valid string HTTPS url 'rpcUrls', Received:
http://127.0.0.1:7545/
code: -32602
message: "Expected an array with at least one valid string HTTPS url 'rpcUrls', Received...
Please let me know how can fix it.
I'll be assuming your code looks like the following:
await ethereum.request({
method: 'wallet_addEthereumChain',
params: [
{
chainId: '0x539',
chainName: 'Gananche',
rpcUrls: 'http://127.0.0.1:7545/'
}
]
});
The rpcUrls value has to be an array, but from your error message it looks like you're passing a string. To fix this, make the value an array as follows:
await ethereum.request({
method: 'wallet_addEthereumChain',
params: [
{
chainId: '0x539',
chainName: 'Gananche',
rpcUrls: ['http://127.0.0.1:7545/'] // Is now an array
}
]
});
you can install localtunnel to tunneling to local HTTPS server
npm install -g localtunnel
and after use the command line interface to request a tunnel to your local server:
lt --port 7545
An url will be created (ex: https://wise-mule-dig-195-131-122-13.loca.lt/)
Open the url created and click on the button "Click to continue"
After you can used this new url instead of http://127.0.0.1:7545/
I have had the same issue and I believe that it is because of the unsafe http url, since it allowed me to pass on the same parameters changing http to https.
So possibly localtunnel might work for you as Patrikoko said?
Another possibility that keeps everything local could be:
https://www.npmjs.com/package/local-ssl-proxy
This serves it with a self signed certificate
In the github readme is says you can serve it with your own trusted certificate as well:
https://github.com/cameronhunter/local-ssl-proxy#readme
local-ssl-proxy --key localhost-key.pem --cert localhost.pem --source 9001 --target 9000

Watson Speech to Text asynchronous http interface - curl / java cannot Register a callback

i am trying to register a callback url with watson STT as below (curl script only) and getting 400 error. node.js process listening on port 3000 to handle request. am i missing something?. Thanks much in Advance.
curl -X POST -u "apikey:xxxxxxxxxxxxxx9xRhxjF2QOqssMkUhLkzl0" "https://api.us-south.speech-to-text.watson.cloud.ibm.com/v1/register_callback?callback_url=http://localhost:3000/results&user_secret=my_secret_key"
{
"code": 400,
"code_description": "Bad Request",
"error": "unsuccessful response from the server"
}

Resources