R
Railway•15mo ago
intbyte

Connect to services using Private Networks

Project ID: 1790d4a8-0e32-4b4e-bf67-6ce23d7ae9e1 I'm trying to connect my main project (Node.js) to a Python API hosted in the same Railway project, according to the logs, my Python project is listening to http://0.0.0.0:3001 and is online on inswapper.railway.internal. I'm not really sure how to connect to the Python API from the main project and most probably misunderstanding how private networking works, so far I tried to make an Axios post request to the endpoint but that returns an ECONNREFUSED error:
/app/node_modules/axios/lib/core/AxiosError.js:89
AxiosError.call(axiosError, error.message, code, config, request, response);
^
AxiosError: connect ECONNREFUSED 0.0.0.0:3001
at Function.AxiosError.from (/app/node_modules/axios/lib/core/AxiosError.js:89:14)
at RedirectableRequest.handleRequestError (/app/node_modules/axios/lib/adapters/http.js:593:25)
at RedirectableRequest.emit (node:events:513:28)
at RedirectableRequest.emit (node:domain:489:12)
at ClientRequest.eventHandlers.<computed> (/app/node_modules/follow-redirects/index.js:14:24)
at ClientRequest.emit (node:events:513:28)
at ClientRequest.emit (node:domain:489:12)
at Socket.socketErrorListener (node:_http_client:494:9)
at Socket.emit (node:events:513:28)
at Socket.emit (node:domain:489:12) {
port: 3001,
address: '0.0.0.0',
syscall: 'connect',
code: 'ECONNREFUSED',
errno: -111,
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: 'http',
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function], Blob: null },
validateStatus: [Function: validateStatus],
headers: Object [AxiosHeaders] {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
'User-Agent': 'axios/1.5.0',
'Content-Length': '174',
'Accept-Encoding': 'gzip, compress, deflate, br'
},
method: 'post',
url: 'http://0.0.0.0:3001/swapper';,
data: '{"source":"","target":"";}'
},
/app/node_modules/axios/lib/core/AxiosError.js:89
AxiosError.call(axiosError, error.message, code, config, request, response);
^
AxiosError: connect ECONNREFUSED 0.0.0.0:3001
at Function.AxiosError.from (/app/node_modules/axios/lib/core/AxiosError.js:89:14)
at RedirectableRequest.handleRequestError (/app/node_modules/axios/lib/adapters/http.js:593:25)
at RedirectableRequest.emit (node:events:513:28)
at RedirectableRequest.emit (node:domain:489:12)
at ClientRequest.eventHandlers.<computed> (/app/node_modules/follow-redirects/index.js:14:24)
at ClientRequest.emit (node:events:513:28)
at ClientRequest.emit (node:domain:489:12)
at Socket.socketErrorListener (node:_http_client:494:9)
at Socket.emit (node:events:513:28)
at Socket.emit (node:domain:489:12) {
port: 3001,
address: '0.0.0.0',
syscall: 'connect',
code: 'ECONNREFUSED',
errno: -111,
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: 'http',
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function], Blob: null },
validateStatus: [Function: validateStatus],
headers: Object [AxiosHeaders] {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
'User-Agent': 'axios/1.5.0',
'Content-Length': '174',
'Accept-Encoding': 'gzip, compress, deflate, br'
},
method: 'post',
url: 'http://0.0.0.0:3001/swapper';,
data: '{"source":"","target":"";}'
},
I also attempted to make a request to http://inswapper.railway.internal:3001/swapper but that resulted in an error as well. This is the code that I use to make requests to the Python API:
axios.post("http://" + process.env.INSWAPPER + "/swapper", {
source: body.source,
target: body.replace,
}).then((data) => {
if (data.data) {
return response.status(200).json({
error: false,
output: data.data.output,
});
}
});
axios.post("http://" + process.env.INSWAPPER + "/swapper", {
source: body.source,
target: body.replace,
}).then((data) => {
if (data.data) {
return response.status(200).json({
error: false,
output: data.data.output,
});
}
});
(I've set process.env.INSWAPPER to both 0.0.0.0:3001 and inswapper.railway.internal:3001, none worked) Also, my Python API takes around 12 minutes to build, it keeps re-installing dependencies (around 5GB I believe) and making deployments slower, is this normal or am I once again doing something wrong?
No description
No description
5 Replies
Percy
Percy•15mo ago
Project ID: 1790d4a8-0e32-4b4e-bf67-6ce23d7ae9e1
jonbeau
jonbeau•15mo ago
I have some suggestions before someone smarter than me comes and tells you the answer 🙂 Although it says HTTP you could try https instead of http. Also have your app listen on the railway provided port environment variable if you aren't already.
intbyte
intbyteOP•15mo ago
Just tried, still the same error as above and as far as im aware the port is set correctly. thanks for the suggestions though!
Ray
Ray•15mo ago
You should bind your server on :: instead of 0.0.0.0, as privnets work over IPv6
intbyte
intbyteOP•15mo ago
If im correct, the server is binded to ::, unless im misunderstanding something...
if __name__ == "__main__":
port_env = os.getenv("PORT", default = 3001);
print(f"Application is listening to port {port_env}");

serve(
app = app,
host = "::",
port = port_env
);
if __name__ == "__main__":
port_env = os.getenv("PORT", default = 3001);
print(f"Application is listening to port {port_env}");

serve(
app = app,
host = "::",
port = port_env
);
Oops, nevermind, misread your message
Want results from more Discord servers?
Add your server