Dockerize sveltekit with pocketbase - node.js

I am trying to dockerize sveltekit app with pocketbase, and in local everything seems to be working,
but in docker non of request passes and I am getting ambiguous error.
Git repo: https://github.com/WingsDevelopment/dockerize-sveltekit-pocketbase/tree/main/my-app
Everything about starting can be found in readme file in repo.
Error:
ClientResponseError 0: Something went wrong while processing your request.
2023-02-16 10:34:53 at new ClientResponseError (file:///app/node_modules/pocketbase/dist/pocketbase.es.mjs:1:2285)
2023-02-16 10:34:53 at file:///app/node_modules/pocketbase/dist/pocketbase.es.mjs:1:40471
2023-02-16 10:34:53 at processTicksAndRejections (node:internal/process/task_queues:96:5)
2023-02-16 10:34:53 at async GET (file:///app/build/server/chunks/_server.ts-49cdad99.js:4:20)
2023-02-16 10:34:53 at async render_endpoint (file:///app/build/server/index.js:1494:22)
2023-02-16 10:34:53 at async resolve (file:///app/build/server/index.js:3671:22)
2023-02-16 10:34:53 at async Object.handle (file:///app/build/server/chunks/hooks.server-8970b6b5.js:8:20)
2023-02-16 10:34:53 at async respond (file:///app/build/server/index.js:3564:22)
2023-02-16 10:34:53 at async Array.ssr (file:///app/build/handler.js:1190:3) {
2023-02-16 10:34:53 url: '',
2023-02-16 10:34:53 status: 0,
2023-02-16 10:34:53 data: {},
2023-02-16 10:34:53 isAbort: false,
2023-02-16 10:34:53 originalError: TypeError: fetch failed
2023-02-16 10:34:53 at fetch (file:///app/build/shims.js:20696:14)
2023-02-16 10:34:53 at processTicksAndRejections (node:internal/process/task_queues:96:5)
2023-02-16 10:34:53 at async GET (file:///app/build/server/chunks/_server.ts-49cdad99.js:4:20)
2023-02-16 10:34:53 at async render_endpoint (file:///app/build/server/index.js:1494:22)
2023-02-16 10:34:53 at async resolve (file:///app/build/server/index.js:3671:22)
2023-02-16 10:34:53 at async Object.handle (file:///app/build/server/chunks/hooks.server-8970b6b5.js:8:20)
2023-02-16 10:34:53 at async respond (file:///app/build/server/index.js:3564:22)
2023-02-16 10:34:53 at async Array.ssr (file:///app/build/handler.js:1190:3) {
2023-02-16 10:34:53 cause: Error: connect ECONNREFUSED 127.0.0.1:8090
2023-02-16 10:34:53 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16) {
2023-02-16 10:34:53 errno: -111,
2023-02-16 10:34:53 code: 'ECONNREFUSED',
2023-02-16 10:34:53 syscall: 'connect',
2023-02-16 10:34:53 address: '127.0.0.1',
2023-02-16 10:34:53 port: 8090
2023-02-16 10:34:53 }
2023-02-16 10:34:53 }
2023-02-16 10:34:53 }

Okay, the problem was with docker, I had 2 images that couldn't comunicate with each other. Fixed it with depend_on in docker compose. Repo is now updated and working... It will remain public

Related

ssl3_get_record:wrong version number, ERPROTO Error when trying to connect using a proxy from an online list

I am trying to connect to a kahoot using a proxy from an online proxy list. The proxy is up, and works just fine so that isn't the problem, but I can't actually connect to it with a request from the code. I've tried using http, https, socks4 and socks5 proxies, all of them return the same error. Is there something I'm missing or need to add? The "options" and "proxy" is just an http request same as what you would see on https://nodejs.org/api/http.html#http_http_request_options_callback
My code:
proxy: (options)=>{
return Object.assign(options,{
host: "51.104.203.226:33800",
});
The full error:
{
description: 'Request failed or timed out.',
error: RequestError: write EPROTO 14200000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:355:
at ClientRequest.<anonymous> (C:\Users\queba\Desktop\kahootspam\node_modules\kahoot.js-latest\node_modules\got\dist\source\core\index.js:970:111)
at Object.onceWrapper (node:events:628:26)
at ClientRequest.emit (node:events:525:35)
at origin.emit (C:\Users\queba\Desktop\kahootspam\node_modules\kahoot.js-latest\node_modules\#szmarczak\http-timer\dist\source\index.js:43:20)
at TLSSocket.socketErrorListener (node:_http_client:494:9)
at TLSSocket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16) {
code: 'EPROTO',
timings: {
start: 1667511954639,
socket: 1667511954641,
lookup: 1667511954765,
connect: 1667511954765,
secureConnect: undefined,
upload: 1667511954893,
response: undefined,
end: undefined,
error: 1667511954894,
abort: undefined,
phases: [Object]
}
}
}

Node JS trying to download a number of images. Stream seems to keep being closed

I'm looping through quite a lot of images to download from a website using this function:
const fileGet = (url, path, callback) => {
request.head(url, (err, res, body) => {
request(url)
.pipe(fs.createWriteStream(path))
})
.on('error', function(err, res) {
console.log(err + res)
})
}
It seems to get so far and then the stream seems to be closed. I've been doing some googling and people mention it could be trying to resolve too many dns lookups in a given time.
This is the error I'm getting:
node:events:371
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND www.domain.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
Emitted 'error' event on Request instance at:
at Request.onerror (node:internal/streams/legacy:62:12)
at Request.emit (node:events:394:28)
at Request.onRequestError (C:\Scraper\node_modules\request\request.js:877:8)
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:193:8)
at emitErrorCloseNT (node:internal/streams/destroy:158:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'www.domain.com'
}
I've tried hard coding the IP/Host name in my Hosts file, and tried putting a pause in the requests, same problem. I've also upgraded to the last version of Node (16.4.0)
Still the same.
There is a lot of debate about this issue online. Has it even been resolved?
Thanks.
If anybody is interested, it was a DNS lookup issue, and sorted it by using DNS Cache.
Just wrapper my whole download process with an initial look up, and the rest ran like a dream.

Recaptcha Handling Throwing Exception Inside Promise with catch

Does anybody know how to handle the error from below properly? Obviously, I am using a 3rd party library that performs an internal HTTP poll to a remote API, sometimes, it throws a connection refusal error and crashes the whole NodeJS process.
return new Promise((resolve, reject) => {
page.getRecaptchaSolutions(captchas).then(({ solutions, solErrors }) => {
if (solErrors)
reject(solErrors);
resolve(solutions)
})
.catch(error => {
reject(new Error(error))
})
})
Error: getaddrinfo EAI_AGAIN 2captcha.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
Emitted 'error' event on ClientRequest instance at:
at Socket.socketErrorListener (_http_client.js:406:9)
at Socket.emit (events.js:223:5)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:81:21) {
errno: 'EAI_AGAIN',
code: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: '2captcha.com'
}

AWS Lambda external URI request error: connect ETIMEDOUT

I coded in my local dev environment a node.js function that does several requests to an external url-uri (asynchronously using bluebird and request-promise). It works fine, the function gets the results and save the information into the EC3 database.
The problem comes when I deploy the code (node modules included), and execute it. It has access to the database, but when tries to access to external url-uri the 'request-promise' module gets an 'connect ETIMEDOUT' error.
I did all the AWS indicates to get it, and read and try a all the solutions I found in Stackoverflow, but still having the problem.
https://www.youtube.com/watch?v=AR1nt3iGR5o
The related role that runs the function has the following policies:
AWSLambdaFullAccess - AWSCodeDeployRoleForLambda - AmazonVPCFullAccess - AWSLambdaExecute - AWSLambdaBasicExecutionRole - AWSLambdaVPCAccessExecutionRole - AWSLambdaRole - oneClick_lambda_basic_execution_1535968782861
Function Network Config
Nat getway
Route Table
Could you help me please, or at least give a hint, please?
CODE:
const Promise = require('bluebird');
const Rp = require('request-promise');
const http = require('http');
var httpAgent = new http.Agent();
httpAgent.maxSockets = 15;
var promises = urls.map(function(url){
return Rp({uri: url.url, pool:httpAgent}).then(function(result){
url.result = result;
// Saving space
delete url.url;
return url;
})
});
Promise.all(promises).then(function(results){
return(processResults(results));
}).catch(Error, function (e) {
console.error("Error doing Request: ", e);
}).error(function (e) {
console.error("Unable get info: ", e);
}).then(function(results){
try{
product.callback(results);
}catch (exception) {
console.error('Error callback: ',exception);
}
}).then(function(){
product.finally();
});
ERROR:
2018-09-28T14:53:48.989Z efb5493a-c32d-11e8-ae42-f73dec33ca2a Error doing Request: { RequestError: Error: connect ETIMEDOUT 147.83.184.65:80
at new RequestError (/var/task/node_modules/request-promise-core/lib/errors.js:14:15)
at Request.plumbing.callback (/var/task/node_modules/request-promise-core/lib/plumbing.js:87:29)
at Request.RP$callback [as _callback] (/var/task/node_modules/request-promise-core/lib/plumbing.js:46:31)
at self.callback (/var/task/node_modules/request/request.js:185:22)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at Request.onRequestError (/var/task/node_modules/request/request.js:881:8)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at Socket.socketErrorListener (_http_client.js:387:9)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
name: 'RequestError',
message: 'Error: connect ETIMEDOUT 147.83.184.65:80',
cause:
{ Error: connect ETIMEDOUT 147.83.184.65:80
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '147.83.184.65',
port: 80 },
error:
{ Error: connect ETIMEDOUT 147.83.184.65:80
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '147.83.184.65',
port: 80 },
options:
{ uri: 'http://geoserver.hydsdev.net/geoserver/mhews/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image%2Fjpeg&TRANSPARENT=true&INFO_FORMAT=text%2Fxml&FEATURE_COUNT=50&X=50&Y=50&SRS=EPSG%3A4326&WIDTH=101&HEIGHT=101&QUERY_LAYERS=mhews:ffews_rain_accumulation_15min_opera&LAYERS=mhews:ffews_rain_accumulation_15min_opera&BBOX=0.6319608%2C42.770155%2C0.8319608%2C42.870155000000004&TIME=2018-09-28T17:30:00.000Z',
pool:
Agent {
domain: null,
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 80,
protocol: 'http:',
options: [Object],
requests: {},
sockets: {},
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: 15,
maxFreeSockets: 256,
'http:': [Object] },
callback: [Function: RP$callback],
transform: undefined,
simple: true,
resolveWithFullResponse: false,
transform2xxOnly: false },
response: undefined }
Cheers.
Finally I fixed the problem. Don't know why but into 'request-promise' options object I have to put: headers: {'User-Agent':'request' } . Thank you very much #Rajesh!

how to use superagent-proxy?

I find it hard to use superagent-proxy, just with the simple code:
const superagent = require('superagent')
require('superagent-proxy')(superagent)
let proxy = 'http://221.237.122.22:8118' // 设置代理
superagent
.get('http://sf.gg')
.proxy(proxy)
.timeout(3600*1000)
.end((err, res) => {
console.log(res)
console.log(res.status, res.headers);
console.log(res.body);
})
but when run, it cannot get an reply, why?
you should:
const superagent = require('superagent')
require('superagent-proxy')(superagent)
let proxy = 'http://221.237.122.22:8118' // 设置代理
superagent
.get('http://sf.gg')
.proxy(proxy)
.timeout(3600*1000)
.end((err, res) => {
if(err) {
console.error(err);
return;
}
console.log(res)
console.log(res.status, res.headers);
console.log(res.body);
})
then, you will get error such as
{ Error: connect ECONNREFUSED 221.237.122.22:8118
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '221.237.122.22',
port: 8118,
response: undefined }
You code is correct, proxy URL is not - if its exactly
'http://221.237.122.22:8118'
it means proxy do not require any login, anybody can use it with just URL, its not the case for most of the proxies, normally proxy URL is like 'http://username:password#IPADDRESS_OR_HOST:PORT'

Resources