how to host python backend with react frontend on railway
Hello, I am new to railway, I am using aiohttp python socketio async server with react frontend. This is error I got:
Nixpacks build failed
Nixpacks was unable to generate a build plan for this app.
Please check the documentation for supported languages: https://nixpacks.com
The contents of the app directory are:
I’ve added a procfile which is : python link to my backend. Is this all I need to add or is there something I am missing. Any help would be appreciated thanks
Getting Started | Nixpacks
App source + Nix packages + Docker = Image
262 Replies
Project ID:
N/A
N/A
can you share a link to your repo?
It’s privated tho it’s basically:
Folder1forbackend:
Inside> myserver.py
Folder2forfrontend:
Inside>
Folder> just some js and html files:
package-lock.json
package.json
.gitignore file
Procfile
This is basically exactly how it’s like
create react app?
There’s also plenty of other files in the folder 2 file for react
But I’m wondering what is the guidelines for hosting this cuz it keeps crashing
?
i could give you exact guide lines if i could see the repo
damn cuz it’s not just my repo
Dk what u mean by this
I’ve created a react app yes
using what? create-react-app or vite
create-react-app pretty sure
can i see a screenshot of the repo lol
you arent giving me much to work with
Alr For sure bro lol my bad
Wanna see something specific
lets focus on getting the frontend running first, so show me a screenshot of the frontend folder
Alright
This my package.json
show me a screenshot of your railway project
I just added GitHub repo didn’t do anything else
remove the repo
Okay
and then show me a screenshot of the project
Sorry, what part of the project?
a screenshot
of the browser
with your project open
railway project
On my phone dam
on your phone, bro go get a computer
aight aight
No charge that’s my bad
are you not near a computer?
Laptop no charge
how are you planning to make changes to the github repo?
Ur right bro thought it would be simple
Was chilling on my bed
get that laptop plugged in
Plugged in 💯
once you got that up and running show me a desktop screenshot of the railway project
100% 🙏
you have removed repo from that service right
yes
google
rename that service to frontend
ok
now follow this guide
https://help.railway.app/project-help/f9v3gkPQRy4UShk5SnoPDH/getting-your-create-react-app-running-on-railway/qHRsgxa5n57xLp1yVgk9fP
once done show me your package.json
alr
is this right?
yes, but show me the full package.json anyway
for sure
bro thats all lmao
no its not lmao
oh wait sent same screenshot
my fault
okay in the frontend service set the root directory to
/frontend
did it
add the repo back to the frontend service
taking sum time
full build logs please
its super long tho
get copy pasting
ok
into a .txt file
aight
☠️
ikr
wait
one sec one sec
full
your lock file is out of sync, run
npm i --package-lock-only
ok
same exact error
delete the lock file entirely and run that command again
aight
got dis
much shorter
run
npm install @tensorflow/tfjs-node
bro tried to do that got a ton of errors
are you even using tesorflow in your frontend app?
no
backend
yea
then why are you importing it in your frontend
did i do that?
somewhere
ye found it
show me your current package.json please
{
"name": "app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.3.3",
"cors": "^2.8.5",
"crypto-js": "^4.1.1",
"js-cookie": "^3.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.0",
"react-scripts": "5.0.1",
"serve": "^14.2.0",
"socket.io-client": "^4.5.4",
"web-vitals": "^2.1.4"
},
"scripts": {
"dev": "react-scripts start",
"start": "serve build -s -n -L -p $PORT",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
cool
awesome
bro thanks a ton btw i hope u getting payed
backend time
show me a screenshot of the backend folder in github
aight
hol on gve me asec
Bro is it cool if we do the backend some other time held up by things completely get it if u cant and u busy appreciate u a lot tho man
sure, send that screenshot when you are ready
@Brody hey this my backend
Apologies on taking a long time
what's a pipfile
what type of app is your backend?
Im using aiohttp
This is the profile
I honestly forgot
aiohttp is nice
heres a template i whipped up for you
https://github.com/brody192/aiohttp-template
ay sup bruh so I added all the files and this is what I got
bruh
"Treating warnings as errors because process.env.CI = true.
#12 19.18 Most CI servers set it automatically.
#12 19.18
#12 19.19 Failed to compile.
#12 19.19"
no no
damn wasup
my template has nothing to do with the frontend
ye ik this error is unrelated
show me a screenshot of the contents of the frontend folder
i have to double check
aight
didnt add nothing to it bro dw
okay you are safe
this the reason
i got the error so
so you wanna do the right thing, or the easy thing?
i guess easy
whatever works
the right thing to do would be to fix the warnings lol
im guessing you dont wanna do that
hol on how i do
the warnings tell you why they are warnings, just fix them lol
oh
hell nah
fine
bro its so long
lazy way
set a service variable
CI
= false
i had to see if youd do the right thing anywayBro u there @Brody
#🛂|readme #5
Sorry bro it’s just I have no idea how to use the template
Lol I know it’s been a while my fault
what template
the aiohttp
its not public lol
keyword: withhold
oh that’s crazy ok
im assuming you have an aiohttp backend already coded that isnt working?
Nah na it’s working
I have a full stack website working
But like
So I’ve hosted it the way u said actually
But just the frontend
The backend ain’t working
you just said it was working
Nah I mean like in my local host it’s working lol
but like when I host it backend not working just frontend
duh
show me screenshot of project in railway please
Yes sir
Broo sorry give me exactly 5 mins
you have 4 and a half
Alr back sending in a bit
here u go bro
where is the backend?
idk how i did that
i just did what u told me fr
i dont remember what i ate for breakfast yesterday, i dont know what ive told you
onesec
ahhhh
ye
mono repo
share the repo again
aight
no like a link to it
alr
ima make it public
i will only spoon
GitHub
GitHub - mrfudgebottom/streamingbear
Contribute to mrfudgebottom/streamingbear development by creating an account on GitHub.
this says flask server, but the stuff is for aiohttp
yeye lol
what framework are you using locally
forgot bout that
its aiohttp
change flask-server to just backend then
been trying then gave up
dk how bro
but its fine honestly can fchange after
change now
also use this .gitignore instead
https://www.toptal.com/developers/gitignore/api/node,python,react,nextjs
aight
delete the pycache folder too
aight
^
broo im actually looking rn google how to do
"how to rename folder" bro
aint no way you googling that
nah on github
rename is locally
push changes
bro im doing on the giothub website dont even have vscoden open☠️
why you make this harder for yourself
idkkk
aight gimme a solid sec
what makes you think the backend is aiohttp
mymachine.py is flask
nah its not check the last couple of lines of code
i did it use it all i can delete that line of code
I was using flask in the beginning thats why
apologies on the confusion
ok done i did it
yes i imported but not running on flask
remove flask
aightt
do you use pipfile locally
i believe so
well pick one, pipfile or requirements.txt
one has to go
ok one second im gonna check if it works ok without it
it wont
whatever you choose, you are missing a whole lot of dependencies from either file type
^
well requirements.txt
okay then delete the pipfiles
nah i mean ill keep the pipfile
and del requirement
gotcha
done
well now add all the needed deps to your pipfile
just these two:
aiohttp==3.8.4
gunicorn==20.1.0
not sure how to do
you choose pipfile without knowing how to do it??
nah btw i didnt add requirements.txt remember u told me to add it
^
Done @Brody
Been extremely busy
how many times i gotta tell you, no pings
alr never again
Would super appreciate the next couple steps bro
you have caught me at a bad time, i am about to head out for a few hours
oh, thats completely fine np👍
in the railway.json file, change the start command to
gunicorn mymachine:app --worker-class aiohttp.GunicornWebWorker --workers 3
aight
just saw this now my bad
done
whats your root dir set to
in the service settings
one sec
/frontend
screenshot of whole project please
ah we haven't created a service for the backend yet
yea
well go ahead and add an empty service
dam how can i do that im unfamiliar
the
+ New
buttonu mean new project?
no
u mean + new variable?
yeah alr
no
new service
blank service
alr just one question where should I click?
start by closing that service lol
aiiiight
yoyooy i found it
give it a name
aight bro
and set the root dir to /backend
bet
then add your github repo
been deploying for sum time should i have patience
bro failed
remove the healthcheck from railway.json
alr
it "Crashed"
shoulkd i just restart
its asking me if I wanna
oh damn nvm worked now
crashed again for some reason
you should send the deploy logs
Yo it’s super long but this error is repeating a ton of times:
File "/app/mymachine.py", line 1, in <module>
from dotenv import load_dotenv
ModuleNotFoundError: No module named 'dotenv
Hold on I’ll fix it
I mean with railway you don't even need .env files
but remember when I said this lol
Yeah nah it’s just that I imported so many things that I’m not using at all
e "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/app/mymachine.py", line 6, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy
Now got this
Alr bro so I’m gonna continue when I wake up cuz super late for me rn 👍
Appreciate u a lot 🙏
Bro for some reason ton of my imports it’s not found. Should i add them to my pipfile somehow and then it’ll work?
that is what I said to do
^
done
you said that last time lol
nah 100%
hol on onesec
bro so webserver detected
but i got a long error
[2023-07-26 18:16:54 +0000] [41] [INFO] Worker exiting (pid: 41)
[2023-07-26 18:16:54 +0000] [1] [WARNING] Worker with pid 42 was terminated due to signal 15
[2023-07-26 18:16:54 +0000] [1] [WARNING] Worker with pid 41 was terminated due to signal 15
[2023-07-26 18:16:54 +0000] [1] [INFO] Shutting down: Master
[2023-07-26 18:16:54 +0000] [1] [INFO] Reason: Worker failed to boot.
it crashed
File "/app/mymachine.py", line 7, in <module>
import torch
File "/opt/venv/lib/python3.10/site-packages/torch/init.py", line 228, in <module>
_load_global_deps()
File "/opt/venv/lib/python3.10/site-packages/torch/init.py", line 189, in _load_global_deps
_preload_cuda_deps(lib_folder, lib_name)
File "/opt/venv/lib/python3.10/site-packages/torch/init.py", line 154, in _preload_cuda_deps
raise ValueError(f"{lib_name} not found in the system path {sys.path}")
ValueError: libcublas.so.*[0-9] not found in the system path ['/app', '/opt/venv/bin', '/root/.nix-profile/lib/python310.zip', '/root/.nix-profile/lib/python3.10', '/root/.nix-profile/lib/python3.10/lib-dynload', '/opt/venv/lib/python3.10/site-packages']
its something about me importing torch not about it being not found
does your app require a GPU?
yea
im pretty sure
then it's not gonna work on railway
oh ok
but double check if it's need the gpu
alr
and if so, maybe there's a way to tell torch to use cpu only
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model.to(device)
i have this. Means if the device has gpu then use that if not then use cpu
well it's not defaulting to cpu it would seem
but try a nixpacks.toml file with this in it
aiight
in backend folder?
yes