when i am testing QUIC i am getting handshake error as opening handshake failed,mywebsite is using cloudflare cdn which support http3 and QUIC too enabled through cloudflare dashboard, please assist
let url = 'https://groundsbooker.com';
//let url = 'https://webrtc.internaut.com:6161/echo';
let transport = new WebTransport(url);
try{
transport.ready.then(()=>{
console.log(`connected to ${url}`);
});
transport.closed.then(()=>{
console.log(`the HTTP/3 connection to ${url} closed gracefully`)
})
}catch(error){
console.log(`connection to ${url} failed to connect with error: ${error}`);
}
Related
I am trying to fetch images from google cloud storage bucket from browser and serving the files using API in express. Following code breaks when the Image path is invalid. The try catch doesn't catch the file not found error. Am I missing something here? This code works if an image file exists.
From the Express side, I am using wildcard route (i.e. /*) as the API can accept any image path coming in and try to serve it.
const express = require('express')
const {Storage} = require('#google-cloud/storage');
let server = express()
const storage = new Storage();
const bucketName = '<some-bucket-name>'
server.get('/*', async (req, res) => {
const widthString = req.query.width
const heightString = req.query.height
const format = req.query.format
const fileName = req.path.substring(1);
console.log("url: ", req.path)
let width, height
if (widthString) {
width = parseInt(widthString)
}
if (heightString) {
height = parseInt(heightString)
}
res.type(`image/${format || 'png'}`)
try{
await storage.bucket(bucketName).file(fileName).createReadStream().pipe(res)
} catch (err) {
console.error(err);
}
})
Error:
url: /media/artist/banner_image/16118/screenshot_2019_12_16_at_10.35.24_am.png
events.js:377
throw er; // Unhandled 'error' event
^
ApiError: No such object: assets/media/artist/banner_image/16118/screenshot_2019_12_16_at_10.35.24_am.png
at new ApiError (/home/ubuntu/imageoptimizer/node_modules/#google-cloud/common/build/src/util.js:73:15)
at Util.parseHttpRespMessage (/home/ubuntu/imageoptimizer/node_modules/#google-cloud/common/build/src/util.js:175:41)
at Util.handleResp (/home/ubuntu/imageoptimizer/node_modules/#google-cloud/common/build/src/util.js:149:76)
at Duplexify.<anonymous> (/home/ubuntu/imageoptimizer/node_modules/#google-cloud/storage/build/src/file.js:888:31)
at Duplexify.emit (events.js:400:28)
at PassThrough.emit (events.js:400:28)
at onResponse (/home/ubuntu/imageoptimizer/node_modules/retry-request/index.js:222:19)
at PassThrough.<anonymous> (/home/ubuntu/imageoptimizer/node_modules/retry-request/index.js:163:11)
at PassThrough.emit (events.js:412:35)
at /home/ubuntu/imageoptimizer/node_modules/teeny-request/build/src/index.js:191:27
Emitted 'error' event on PassThrough instance at:
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
code: 404,
Posting my previous comment as an answer for visibility
You have to handle this exception by yourself. GCP won't throw the error directly. It only returns 404 as an output, and you have to handle it manually rather than expecting try{} catch () {} to catch this exception. Or you can request it as a new feature in issue tracker, however I am not sure how long it will take for the Google to implement this feature.
I have a simple .NET Core WebAPI with no authentication. I added Cors with default policy. I have no problem connecting and fetching data from my React website or Postman (everything runs locally on my machine). Now I'm trying to fetch data from that API in super simple node application and I'm getting this error:
file:///Users/aw/Projects/TestNodeApp/node_modules/node-fetch/src/index.js:94
reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, 'system', error));
^
FetchError: request to https://localhost:5001/api/teams failed, reason: self signed certificate
at ClientRequest.<anonymous> (file:///Users/aw/Projects/TestNodeApp/node_modules/node-fetch/src/index.js:94:11)
at ClientRequest.emit (node:events:394:28)
at TLSSocket.socketErrorListener (node:_http_client:447:9)
at TLSSocket.emit (node:events:394:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
type: 'system',
errno: 'DEPTH_ZERO_SELF_SIGNED_CERT',
code: 'DEPTH_ZERO_SELF_SIGNED_CERT',
erroredSysCall: undefined
}
This is my whole node application:
import fetch from 'node-fetch';
async function fetchTeams() {
const response = await fetch('https://localhost:5001/api/teams', { method: 'GET' });
const data = await response.json();
return data;
}
(async () => {
console.log('Process started');
const teams = await fetchTeams();
console.log(teams);
})().finally(() => {
console.log('Process finished');
});
What does it mean? What Am I missing?
Btw. It works fine, when I'm fetching Github API, like this:
async function fetchGithub() {
const response = await fetch('https://api.github.com/users/Microsoft');
const data = await response.json();
return data;
}
So I assume, something is missing in the API. Something that my React website doesn't need, that node app needs.
Thanks for help!
You can use this command to set the NODE_TLS_REJECT_UNAUTHORIZED environment variable:
export NODE_TLS_REJECT_UNAUTHORIZED=0
Try trusting the self signed certificate with dotnet dev-certs
dotnet dev-certs https --trust
For more details please visit this documentation page.
I created a secure websocket using this,
const Socket = require("websocket").server
const https = require("tls")
const fs = require('fs');
//certificate information
const certificate = {
cert: fs.readFileSync("/home/WebRTC/ssl/webrtc.crt",'utf8'),
key: fs.readFileSync("/home/WebRTC/ssl/webrtc.key",'utf8')
};
const server = https.createServer(certificate,(req, res) => {})
server.listen(3000, () => {
console.log("Listening on port 3000...")
})
const webSocket = new Socket({ httpServer: server })
and created the web client using this,
const webSocket = new WebSocket("wss://ip:3000")
webSocket.onerror= (event) => {
alert("Connection error occured");
}
webSocket.onopen = (event) =>{
alert("Connection established");
}
webSocket.onmessage = (event) => {
alert("Message received");
}
Im using https. Created a self signed certificate
wss://ip:3000. here the IP is the certificate resolving IP. These files are hosted in a publicly accessible server
But when I put the request, it takes a lot of time and gives and error.
"WebSocket connection to 'wss://ip:3000/' failed: "
Please be kind enough to help
when I send a get request on postman session id is not generated instead it goes on catch block and shows an error occured, please help me solve this problem
const authenticator = new IamAuthenticator({
apikey: process.env.WA_ASSISTANT_APIKEY,
});
const assistant = new AssistantV2({
version: "2019-02-28",
authenticator: authenticator,
url: process.env.WA_ASSISTANT_APIKEY,
});
router.get("/session", async (req, res) => {
//if successfull
try{
const session = await assistant.createSession({
assistantId: process.env.WA_ASSISTANT_ID,
});
res.json(session["result"]);
//error
}catch(err){
res.send("An Error occured while processiong your request!");
console.log(err);
}
})
This is the code
Error
The error suggests that your app is trying to connect to Watson Assistant on localhost. I suspect the error is due to your line -
url: process.env.WA_ASSISTANT_APIKEY
APIKey is very unlikely to be a url.
I want to know how two systems can communicate over tcp.
I have node.js tcp client and server codes. When tested on the same machine, the applications work well.
The problem is when I try to run the server code on one machine and the client code on another machine, no connection is established.
The two PCs are running on Windows and are connected using switch. They can share resources.
Please any help to understand how this things work is highly appreciated.
Here is the server code
const tcpServer = net.createServer();
const PORT = 3030;
const HOSTNAME = '169.254.142.199';
tcpServer.on('listening', () => {
console.log(`Server listening on port ${PORT}`, tcpServer.address());
})
tcpServer.on('connection', socket => {
console.log(`Server connected to client on localport ${socket.localPort} and remotePort ${socket.remotePort}`);
socket.on('error', err => {
console.log(`error occured ${err.message}`);
})
socket.write('Hi Welcome');
});
tcpServer.once('close', () => {
console.log('connection closed');
});
tcpServer.on('error', err => {
console.log(`error occured ${err.message}`);
});
tcpServer.listen(PORT, HOSTNAME);
Here is the client code
const PORT = 3030;
const HOSTNAME = '169.254.142.199';
const tcpClient = net.createConnection(PORT, HOSTNAME, () => {
console.log(`connected to server on port ${PORT}`, tcpClient.address());
});
tcpClient.on('error', err => {
console.log(`error occured: ${err.message}`);
})
tcpClient.on('close', err => {
console.log(`connection closed ${err ? 'with' : 'without'} error`);
})
tcpClient.on('data', data => {
console.log('%s', data);
})
169.254.142.199 is the IP address of the PC running the server code.
The error message is error occured: connect ECONNREFUSED 169.254.142.199:3030
What am I doing wrong? Where am I missing it?
Thanks for your help.
Finally it has worked.
I turned off Windows firewall and communication went through.
thanks to everyone.