Nginx with my web application
Hello there! Been trying out a few different services to see where I want to host my web app.
Frontend: React
Backend: Golang
I've got the backend up and running without any issues. I'm having some trouble getting my frond end up and running. I've tried with/without a docker file. Currently with the dockerfile the application is building fine, but crashes.
Error:
Dockerfile:
nginx.conf
From what I can tell from the docs and other support tickets something like this should be possible. Just not sure what I'm missing.
Thank you for any help!
66 Replies
Project ID:
cc7cfdf3-8735-4236-8e74-0d7398ca6dc3
cc7cfdf3-8735-4236-8e74-0d7398ca6dc3
create react app?
Not sure I understand the question sorry. Yes, the front end is React
was it made with create react app?
or react scripts, however you wanna call it
Ahhh, I beleve so. It's been a while since I initialized it.
Probably something like
npx create-react-app my-app --template typescript
does the api endpoint have to live on the same domain as the frontend?
No, but it's preferred.
I can do something like
api.my_domain.com
if I have to, but I'd prefer my_domain.com/api
okay fair enough
okay so let's get started
show me a screenshot of your railway project so I know what we are working with
Just this?
yep that's it
can I see a screenshot of the frontend project in github?
just the files and stuff
looking good
I'm gathering information so I can work out the best course of action
does the client have a public domain?
You mean like here? Not yet, but I do have a domain I will use
generate one, just for testing
client-staging-13a0.up.railway.app
delete the Dockerfile and nginx.conf from your repo.
https://github.com/brody192/create-react-app-starter
copy the nixpacks.toml and Caddyfile from this repo into yours.
if you have any custom build or start commands set in the clients service settings, please remove them.
after that, let me know the outcome
if that works the next step will be to join the frontend and backend under one domain, but one step at a time
Build failed
I'm assuming it's because there's a few warnings that I have not cleaned up yet.
#19 77.49 Treating warnings as errors because process.env.CI = true.
I'm new to Caddyfile, is there somewhere I can update this so it ignores warnings for now?Caddyfile has nothing to do with building your site.
set a service variable
CI
to false
Ahhh okay, will let that build.
side note, please use this for sending me your build logs https://bookmarklets.up.railway.app/log-downloader/
the log snippet you sent didn't have any useful information.
Okay, looks like the build worked and the app is live via the url I sent above.
awesome, send another screenshot of the project please
do you have a
PORT
service variable set on the server service?do you have a PORT service variable set on the server service?In railway? no
can you show me the server code that starts listening?
what is the server domain set to
Just the domain I want to use for the application
please show me
Show you how?
I have an env variable set up in railway that it picks up.
screenshot please
show me the value
on second thought, please use this code instead of what you currently have, that way we know it's correct
I'm not going to need a domain on that?
nope
a domain isn't applicable here, and if you say it worked on railway I will be shocked
but then again, for some reason, you never did tell me what you had it set to
I had it set to my domain (with no port).
again, that's not telling me what it's set to
I don't understand the secrecy, but either way, please use the code I provided instead
Just not a domain I wanted to share. I'm not sure why knowing the exact domain matters. Could be
my_domain.com
and it wouldn't really make a difference.
Updated the code. Waiting for it to buildI understand that but details matter when dealing with these things, omitting details has dramatically increased the time it takes to resolve this and other help threads
Okay, server built and is active.
does it work?
Do you mean does the client call it? No
no, just the backend, does it work on its own?
on the client service, set a
PORT
service variable to 3000
on the server service, set a PORT
service variable to 3001
Okay that's done
go ahead and deploy the
reverse proxy
template into your project.
for the FRONTEND_HOST
variable, use http://${{Client.RAILWAY_PRIVATE_DOMAIN}}:${{Client.PORT}}
for the BACKEND_HOST
variable, use http://${{Server.RAILWAY_PRIVATE_DOMAIN}}:${{Server.PORT}}
Deploying
What does the
ENABLE_ALPINE_PRIVATE_NETWORKING
env variable do? I'm not seeing it referenced in the reverse proxy codethere was a hyperlink under it that linked to docs explaining what it does
but for the end user, you can ignore it
so now you can remove the public domains from the server and client services because they will no longer be accessed publicly. you now use the domain on the proxy service
So I would just add my custom domain to the proxy service then? Instead of the client?
correct
Is this generally the expected deploy time for the proxy?
not at all
did you missconfigure something?
Let me double check
I noticed I was missing the
http://
on the env variables. I added that, but it seems the health check is still failing on the serverfull screenshot of your project please
why is the health check failing
you might need to make changes to the Caddyfile, please have a read of the comments in the Caddyfile
This is the correct health check plan? It was what it was set to when I created the template.
your backend does have an
/api/
path right?No, just figured this out. I updated it to
/api/ping
. That fixed it.okay now that's good
so we in business?
We are good!
Thank you so much for your help! Greatly appriciated!
happy to help!