R
Railway12mo ago
Satan1c

can't reach site runs on Drogon

according to logs, Drogon runs successfully, but when I try to open the site, I get "Application failed to respond".
39 Replies
Percy
Percy12mo ago
Project ID: 8c09c3c7-3c6b-469e-98a6-32062758ed19
Satan1c
Satan1c12mo ago
8c09c3c7-3c6b-469e-98a6-32062758ed19
Satan1c
Satan1c12mo ago
in application I'm already use 0.0.0.0 as host and 80 port according to guide now I set PORT variable as 80, but nothing changes
Brody
Brody12mo ago
that is actually not recommended you should ideally not be setting a PORT variable yourself please show me the app().addListener line
Satan1c
Satan1c12mo ago
int main() {
drogon::app()
.setLogLevel(trantor::Logger::LogLevel::kTrace)
.addListener("0.0.0.0", 80)
.setThreadNum(0)
.enableBrotli(true)
.enableSession(24h)
#if WIN32
.run();
#else
.enableRunAsDaemon()
.run();
#endif

return 0;
}
int main() {
drogon::app()
.setLogLevel(trantor::Logger::LogLevel::kTrace)
.addListener("0.0.0.0", 80)
.setThreadNum(0)
.enableBrotli(true)
.enableSession(24h)
#if WIN32
.run();
#else
.enableRunAsDaemon()
.run();
#endif

return 0;
}
Brody
Brody12mo ago
this docs page will help you https://docs.railway.app/troubleshoot/fixing-common-errors just to clearly reiterate on what that docs page wants you to do, listen on the environment variable PORT in your code
Satan1c
Satan1c12mo ago
you mean that I need to get env var in code ? oh, I get that
Brody
Brody12mo ago
yes, there are code examples at the bottom, none for c++ but that still gives you an idea of what needs to be done
Satan1c
Satan1c12mo ago
railway has its own hidden PORT var earlier for my ASP.NET site I just set PORT var by my self k, I'll try
Brody
Brody12mo ago
that is not the recommended method
Satan1c
Satan1c12mo ago
from railway I got 5563 port, but I still can't access to site
Brody
Brody12mo ago
show me the code please same bit of code you've already shown me
Satan1c
Satan1c12mo ago
int main() {
uint16_t port = std::stoi(getenv("PORT"));
LOG_DEBUG << port << " port";
drogon::app()
.setLogLevel(trantor::Logger::LogLevel::kTrace)
.addListener("0.0.0.0", port)
.setThreadNum(0)
.enableBrotli(true)
.enableSession(24h)
#if WIN32
.run();
#else
.enableRunAsDaemon()
.run();
#endif

return 0;
}
int main() {
uint16_t port = std::stoi(getenv("PORT"));
LOG_DEBUG << port << " port";
drogon::app()
.setLogLevel(trantor::Logger::LogLevel::kTrace)
.addListener("0.0.0.0", port)
.setThreadNum(0)
.enableBrotli(true)
.enableSession(24h)
#if WIN32
.run();
#else
.enableRunAsDaemon()
.run();
#endif

return 0;
}
Brody
Brody12mo ago
looks good now, does this start an http server?
Satan1c
Satan1c12mo ago
yep I guess
Brody
Brody12mo ago
you guess?
Satan1c
Satan1c12mo ago
but strange that I don't see log about home controller... when I run it locally it shows it I've different logs locally and on railway locally I've no
20230714 15:24:01.086848 UTC 1 TRACE [run] Start to run... - HttpAppFrameworkImpl.cc:454
Initializing daemon mode
20230714 15:24:01.086848 UTC 1 TRACE [run] Start to run... - HttpAppFrameworkImpl.cc:454
Initializing daemon mode
logs I've that
20230714 15:21:43.439000 UTC 15128 DEBUG [main] 80 port - main.cc:7
20230714 15:21:43.630000 UTC 15128 DEBUG [HomeCtrl] Home constructor! - headers/HomeCtrl.h:18
20230714 15:21:43.439000 UTC 15128 DEBUG [main] 80 port - main.cc:7
20230714 15:21:43.630000 UTC 15128 DEBUG [HomeCtrl] Home constructor! - headers/HomeCtrl.h:18
Brody
Brody12mo ago
why the enable run as deamon? when not on windows
Satan1c
Satan1c12mo ago
locally I can't run daemon, but why I don't get "run" log idk
Brody
Brody12mo ago
why do you want to run the deamon anywhere
Satan1c
Satan1c12mo ago
wouldn't it be better that default run ? k, I'll try to run it normally on railway
Brody
Brody12mo ago
I don't know, tell me the differences? I'm not a cpp dev
Satan1c
Satan1c12mo ago
as I understand, daemon mode, is designed for background web-services so I guess it'll be better to run server as daemon
Brody
Brody12mo ago
what makes you think you should run your app as a background service?
Satan1c
Satan1c12mo ago
idk how on linux, but on windows background tasks runs in different priority of resources so I'd like that my app consume as small amount of them as it can
Brody
Brody12mo ago
I see your thought process, but that's not quite how it works
Satan1c
Satan1c12mo ago
that's like "child trauma" after ASP.NET, that allocating +-300-400mb RAM for empty project)
Brody
Brody12mo ago
I mean that can be solved by simply not using languages and frameworks that are known to use a lot of resources
Satan1c
Satan1c12mo ago
I've two main points to use cpp 1. is learn something new 2. create more efficient site, bot etc
Brody
Brody12mo ago
what's the memory usage like for a cpp app that uses drogon?
Satan1c
Satan1c12mo ago
I was interested in cpp few years ago, but chanse to "tuch" it came only now) for now, for empty app, +-3mb, I guess it'll about 20-50mb after I'll end with transfer from ASP
Brody
Brody12mo ago
ay now that's awesome
Satan1c
Satan1c12mo ago
in case of ASP, only runtime allocates +-100-150mb of RAM, other 100-200mb allocates to some ASP services just cuz of GC, app will allocate +-300-400 for long time, without clearing I tried to raise GC collections manually, and it clear up RAM back to 100-150 but by the time, ASP again creating lots of trash in case of cpp, and drogon, all memory clears immediately, an it doesn't need any runtime so app allocates as small amount of resources as it really needs
Brody
Brody12mo ago
thats no fun
Satan1c
Satan1c12mo ago
yep, I remove daemon mode and it runs fine
Brody
Brody12mo ago
awsome!
Satan1c
Satan1c12mo ago
thx for helping <3
Brody
Brody12mo ago
enjoy the cheaper railway bills too!