R
Railway16mo ago
guoyuyan

redis

How to connect Redis by railway connect, does a template exist to connect Redis with railway connect? Now I connect with username/password, but I'm finding a way to connect without a username. ProjectId: 38fe79a8-c127-4e50-ba67-eab1ce076502 ServiceId: e95b93c0-d4a0-4be2-8a1b-2addbf59d616
40 Replies
Percy
Percy16mo ago
Project ID: 38fe79a8-c127-4e50-ba67-eab1ce076502
guoyuyan
guoyuyan16mo ago
38fe79a8-c127-4e50-ba67-eab1ce076502
Brody
Brody16mo ago
there would need to be a redis plugin in the project you've linked with the cli railway connect should not ask you for a username or password to connect to redis, since that would defeat the purpose of the command
guoyuyan
guoyuyan16mo ago
You mean railway connect is an interactive input to connect Redis? It also needs username and password?
Brody
Brody16mo ago
it does not need a username or password
guoyuyan
guoyuyan16mo ago
sorry, I miss not, where is the plugin?
Brody
Brody16mo ago
have you created a project in railway?
guoyuyan
guoyuyan16mo ago
yes, 38fe79a8-c127-4e50-ba67-eab1ce076502 is the project id
Brody
Brody16mo ago
does that project have a redis plugin in it? (I'm just a community member I can't see anything about your project with your id)
guoyuyan
guoyuyan16mo ago
I add a redis server, but I don't know what is redis plugin.
guoyuyan
guoyuyan16mo ago
Brody
Brody16mo ago
a plugin is just the name we give to the provided databases, mysql plugin, mongodb plugin, etc but yeah that looks good to me do you have the railway cli installed on your computer?
guoyuyan
guoyuyan16mo ago
I want to use railway connect in the kuai server but not on my computer. Currently, I use the variable to connect it.
Brody
Brody16mo ago
railway connect is for your computer, I think you're mistaken if you want to connect to the redis database from your kuai service you are going to first need to setup all the needed variable references for redis https://docs.railway.app/develop/variables#reference-variables
guoyuyan
guoyuyan16mo ago
got that, I mistake thought there is exist one way to connect it to other services without username/password
Brody
Brody16mo ago
please do that and then show me another screenshot of your service variables
guoyuyan
guoyuyan16mo ago
I have connected Redis success with variables. Thank you for your help. I mistake thought that railway connect is used for other services.
Brody
Brody16mo ago
so all good, problem solved?
guoyuyan
guoyuyan16mo ago
yes, I have another problem with the private network between the two services. Do you have a template that how to use a private network?
Brody
Brody16mo ago
I do, but I'm gonna need more information on your desired usecase
guoyuyan
guoyuyan16mo ago
The kuai-mvp-dapp-ui is created by next, the kuai service is created by Koa, and I want to call kuai api by private network from kuai-mvp-dapp-ui
Brody
Brody16mo ago
okay one sec while I Google what Koa is okay Koa is express but better
guoyuyan
guoyuyan16mo ago
I have set all of the service hosts to ipv6(::1), but it seems not to call kuai success by a private network. And after I set host to ::1, the public service is also failed.
Brody
Brody16mo ago
so this request would need to be done by the next backend, the client browser of the site will not be able to call the private network, wouldnt be very private if that was possible can you show me the line of code that contains your app.listen call?
guoyuyan
guoyuyan16mo ago
const server = app.listen(port, host, function () {
const address = (() => {
const _address = server.address()
if (!_address) {
return ''
}

if (typeof _address === 'string') {
return _address
}

return `http://${_address.address}:${_address.port}`
})()

console.info(`kuai app listening to ${address}`)
})
const server = app.listen(port, host, function () {
const address = (() => {
const _address = server.address()
if (!_address) {
return ''
}

if (typeof _address === 'string') {
return _address
}

return `http://${_address.address}:${_address.port}`
})()

console.info(`kuai app listening to ${address}`)
})
the port and host is from variable
Brody
Brody16mo ago
and what is host and port set to?
guoyuyan
guoyuyan16mo ago
Brody
Brody16mo ago
delete both those variables and use this code instead
const port = process.env.PORT || 3000;

const server = app.listen(port, '::', function () {
const address = (() => {
const _address = server.address();
if (!_address) {
return '';
}

if (typeof _address === 'string') {
return _address;
}

return `http://${_address.address}:${_address.port}`;
})()

console.info(`kuai app listening to ${address}`);
});
const port = process.env.PORT || 3000;

const server = app.listen(port, '::', function () {
const address = (() => {
const _address = server.address();
if (!_address) {
return '';
}

if (typeof _address === 'string') {
return _address;
}

return `http://${_address.address}:${_address.port}`;
})()

console.info(`kuai app listening to ${address}`);
});
guoyuyan
guoyuyan16mo ago
thanks, I will try
Brody
Brody16mo ago
and you are calling the koa service from the next backend right?
guoyuyan
guoyuyan16mo ago
actually, in the next front end.
Brody
Brody16mo ago
thats not possible
guoyuyan
guoyuyan16mo ago
Should I use nginx to proxy these two service?
Brody
Brody16mo ago
wait let me rephrase that question are you going to be calling the koa service's private domain from the next backend?
guoyuyan
guoyuyan16mo ago
I guess I need proxy the request from next, otherwise, the request will send from the browser to koa service, and the browser cannot visit the private network. Am I right?
Brody
Brody16mo ago
you are correct, but you dont need a proxy, just call the koa public domain
guoyuyan
guoyuyan16mo ago
That's right, if I don't want to expose the koa, I need a proxy.
Brody
Brody16mo ago
you do need to expose the koa service though a proxy is just exposing the service with extra steps, it doesnt add any of the security benifts you think it would
guoyuyan
guoyuyan16mo ago
You are correct. Thank you very much. Have a good day.
Brody
Brody16mo ago
well that was easy, i thought id need to do some more convincing glad i could help!
Want results from more Discord servers?
Add your server