R
Railway15mo ago
Chioma

Help setup a monorepo - Angular / Express

Hi! Hope everyone is doing well :). I am trying to deploy my Angular application on railway, but it immediately fails every time with the following error message: [us-west1] ==================================== Banned Dependency Detected! ==================================== tgvc tgvc Please remove this dependency from your project to use it on Railway In Visual Studios Code, I have done a global search in my application for "tgvc", and I do not see anything in my project folder. I am very lost on this error, so if I could have an guidance on solving this problem please it would be greatly appreciated. I would love to get my app deployed! My Github Repo is: https://github.com/ChiomaGrace/MyPortfolio/tree/master/src/app Thank you in advance!!
GitHub
MyPortfolio/src/app at master · ChiomaGrace/MyPortfolio
Contribute to ChiomaGrace/MyPortfolio development by creating an account on GitHub.
414 Replies
Percy
Percy15mo ago
Project ID: 48355b37-3634-48fd-88d5-92176fc780eb
Chioma
ChiomaOP15mo ago
My project ID is 48355b37-3634-48fd-88d5-92176fc780eb
Brody
Brody15mo ago
whats going on with your package.json?? its looking like a lock file https://github.com/ChiomaGrace/MyPortfolio/blob/master/package.json
Chioma
ChiomaOP15mo ago
Hi Brody! Thank you for replying so quickly. I don't know... When I was initially trying to deploy, I was getting errors that I was looking up on StackOverflow to debug. One of my errors was "TSC not found in Docker build" I went to this Stack Overflow link (https://stackoverflow.com/questions/67199539/tsc-not-found-in-docker-build), and I ran the command the user Diogo suggested at the bottom: RUN npm install --only=production && npm cache clean --force && npm install -g typescript This completely broke my app locally, and I couldn't run it with either ng serve or ng build. I resolved that issue and can see my app locally again, but I fee like the command I ran then still caused unwanted changes. Do you think this is why I can't deploy now?
Stack Overflow
TSC not found in Docker build
When building an image that needs to be compiled from typescript, I get this error. sh: 1: tsc: not found The command '/bin/sh -c npm run tsc' returned a non-zero code: 127 Here is the relevant ...
No description
Brody
Brody15mo ago
that command was not meant for you to run locally
Chioma
ChiomaOP15mo ago
Ah okay... I didn't know that. Do you by chance know how I can fix my package.json and get the deployment done successfully?
Brody
Brody15mo ago
i was gonna say look at the github history, but the oldest comment still has the borked package.json so give this package.json a try
{
"name": "my-portfolio",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"dev": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"dependencies": {
"@angular/core": "^16.2.4",
"@angular/forms": "^16.2.4",
"@angular/platform-browser-dynamic": "^16.2.4",
"@angular/router": "^16.2.4",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"font-awesome": "^4.7.0",
"jquery": "^3.7.1",
"router": "^1.3.8"
},
"devDependencies": {
"@angular-devkit/build-angular": "^16.2.1",
"@fortawesome/fontawesome-free": "^6.4.2",
"@types/jquery": "^3.5.18"
}
}
{
"name": "my-portfolio",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"dev": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"dependencies": {
"@angular/core": "^16.2.4",
"@angular/forms": "^16.2.4",
"@angular/platform-browser-dynamic": "^16.2.4",
"@angular/router": "^16.2.4",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"font-awesome": "^4.7.0",
"jquery": "^3.7.1",
"router": "^1.3.8"
},
"devDependencies": {
"@angular-devkit/build-angular": "^16.2.1",
"@fortawesome/fontawesome-free": "^6.4.2",
"@types/jquery": "^3.5.18"
}
}
its also probably worth it to delete your node_modules folder and run npm install
Chioma
ChiomaOP15mo ago
Okay I will do that right now and will return with an update shortly. Thank you!
Chioma
ChiomaOP15mo ago
Hi Brody! I am back. The build failed again, but the error is different. The error is now: [us-west1] ============== Using Nixpacks ============== context: 7de9f9017b9882db533fd8b598164067 Nixpacks build failed ╔═════════ Nixpacks v1.14.0 ════════╗ ║ setup │ nodejs-16_x, npm-9_x ║ ║───────────────────────────────────║ ║ install │ npm ci ║ ║───────────────────────────────────║ ║ build │ npm run build ║ ║───────────────────────────────────║ ║ start │ ║ ╚═══════════════════════════════════╝ Error: No start command could be found
No description
Brody
Brody15mo ago
copy the Caddyfile and the nixpacks.toml from this repo, into yours https://github.com/brody192/angular-template make sure you change dist/my-portfolio to just dist https://github.com/ChiomaGrace/MyPortfolio/blob/master/angular.json#L16
Chioma
ChiomaOP15mo ago
Okay. I am doing that now
Chioma
ChiomaOP15mo ago
Would I need to change it to only dist here too? Or no
No description
Brody
Brody15mo ago
oh this is like a monorepo but instead of the two services being separate, they're both jumbled together to properly deploy this on Railway please separate the frontend and backend into their own folders
Chioma
ChiomaOP15mo ago
I have made your suggested changes, and the error is the same I think I do have my front end and back end separate!
Brody
Brody15mo ago
you can keep them in the same repo, just put them into backend and frontend folders
Chioma
ChiomaOP15mo ago
Apologies. I don't think I understand
Brody
Brody15mo ago
No description
Brody
Brody15mo ago
like so
Chioma
ChiomaOP15mo ago
okay. and i literally need to name these folders frontend and backend will this disrupt ng serve if i want to work locally again?
Brody
Brody15mo ago
well is that what this repo contains? a frontend and a backend?
Chioma
ChiomaOP15mo ago
yes i destrcutured all my server files are in a server folder
Brody
Brody15mo ago
no, you'd just end up running ng serve while in the frontend folder so please go ahead and organize everything into either a frontend folder or a backend folder
Chioma
ChiomaOP15mo ago
okay i did not add those folders just yet. i rechecked that i put those two files you wanted me to grab from Github in the correct spot, and i did not. i moved them, and then railway tried to deploy again. this is now the error
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
you will continue to get errors from railway until your repo is in the correct state, please go ahead and remove the repo from the railway service, this can be done by clicking the little X on the repo in the service settings
Chioma
ChiomaOP15mo ago
okay thanks. I understand what you're saying! but i am trying to say the error is different it is something about docker build. Does this require a different solution than the one you were telling before?
Brody
Brody15mo ago
at this stage the error is kinda irrelevant 🤣 please remove the repo from the service, you are going to be making a lot of changes to the repo and you don't need railway to rebuild on every change for now
Chioma
ChiomaOP15mo ago
okay that makes sense let me do that now
Brody
Brody15mo ago
after that please get your repo into this type of folder structure
Chioma
ChiomaOP15mo ago
Okay I have restructured, and I got this dialog popup. Should I say yes?
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
no but from your screenshot, that's not even remotely close to the structure in the tree image
Chioma
ChiomaOP15mo ago
i guess i am not understanding then my server folder has my routes, controller, and model is that not the same as a backend folder?
Brody
Brody15mo ago
in the root of your repo, you should have a backend folder and a frontend folder, nothing more in the frontend folder you should have only the code for your frontend in the backend folder you should have only the code for your backend
Chioma
ChiomaOP15mo ago
it is an angular app with express backend
Brody
Brody15mo ago
yes it is
Chioma
ChiomaOP15mo ago
so when you say all front end code
Brody
Brody15mo ago
all angular code goes in a frontend folder all express code goes in a backend folder
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
that would need to end up within a frontend folder, yes
Chioma
ChiomaOP15mo ago
i just dont understand why i am doing it "app" is all the front end my server is all back end
Brody
Brody15mo ago
angular and express are two different technologies, you currently have them all mashed together, you need to separate them into their respective folders or railway will never be able to properly deploy your apps, so please trust me on this I've been through this process many many times
Chioma
ChiomaOP15mo ago
okay Brody...I will do it! I'll send a screenshot shortly to show you
Brody
Brody15mo ago
you have removed the github repo from the service, so you can commit your changes directly to github so I can see it like that
Chioma
ChiomaOP15mo ago
okay it is not allowing me to move the src folder that contains all my components/.ts files/etc
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
just move it around with the file explorer
Chioma
ChiomaOP15mo ago
okay i have moved everything it's not happy with me when i open vs code though. should i push to github so you can see
Brody
Brody15mo ago
push the changes
Brody
Brody15mo ago
in the root of your repo, you should have a backend folder and a frontend folder, nothing more in the frontend folder you should have only the code for your frontend in the backend folder you should have only the code for your backend
Chioma
ChiomaOP15mo ago
Brody I am so confused haha. I am sorry. I don't understand how I didn't do that Can you say the specific file you want in each folder please?
Brody
Brody15mo ago
you should have a frontend and a backend folder, absolutely nothing more in the root
Chioma
ChiomaOP15mo ago
OH
Brody
Brody15mo ago
your angular and express apps are two separate things, they need to be in separate folders
Chioma
ChiomaOP15mo ago
Even though this is how I have it in VS Code:
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
I see the backend folder in github
Chioma
ChiomaOP15mo ago
oh okay does everything look structured how you asked now?sorry again for not understanding and thank you for being patient and helping me i appreciate it
Brody
Brody15mo ago
there's this angular cache folder thing in the repo, go ahead and delete that (there's still tons more to do, but one thing a time)
Chioma
ChiomaOP15mo ago
deleted
Brody
Brody15mo ago
you'd need to delete it from the repo
Chioma
ChiomaOP15mo ago
would you like me to do that now? or add more to this change first
Brody
Brody15mo ago
one thing at a time, so delete that cache folder thing
Chioma
ChiomaOP15mo ago
right on. i pushed that to repo now
Brody
Brody15mo ago
so now let's focus on the backend it's missing a .gitignore you can use this for your .gitignore https://www.toptal.com/developers/gitignore/api/node
Brody
Brody15mo ago
haha you dont have to keep sending me the commits, you can just say done and ill refresh my browser
Chioma
ChiomaOP15mo ago
haha okay sorry about that
Brody
Brody15mo ago
well now you are missing a package json, do an npm init, then install all the packages this express app uses
Chioma
ChiomaOP15mo ago
i need to do this in the backend folder now right? and not in the myportfolio folder
Brody
Brody15mo ago
(we are still working in the backend folder)
Chioma
ChiomaOP15mo ago
I ran npm init. In terms of installing all the packages would an npm install work for this, or is there something else needed?
Brody
Brody15mo ago
npm install express, etc etc go ahead an install all librarys you are using for the backend only
Chioma
ChiomaOP15mo ago
i think that is just express and mongoose
Brody
Brody15mo ago
sounds good
Chioma
ChiomaOP15mo ago
done
Brody
Brody15mo ago
change this https://github.com/ChiomaGrace/MyPortfolio/blob/master/backend/server.js#L4 to const port = process.env.PORT || 3000;
Chioma
ChiomaOP15mo ago
done
Brody
Brody15mo ago
now locally while inside the backend folder, can you run the server? npm run start
Chioma
ChiomaOP15mo ago
sort of! MongooseError: Mongoose.prototype.connect() no longer accepts a callback i think i was using a older verison of mongoose might have to install that one again
Chioma
ChiomaOP15mo ago
okay yup i can run the node server now
Brody
Brody15mo ago
this is a public repo
Chioma
ChiomaOP15mo ago
okay. do you want me to change it now?
Brody
Brody15mo ago
its a short process to do it right screenshot of your railway project please
Chioma
ChiomaOP15mo ago
i deleted it shall i make another?
Brody
Brody15mo ago
why lol
Chioma
ChiomaOP15mo ago
good question haha
Brody
Brody15mo ago
sure make a another project blank project no github stuff yet
Chioma
ChiomaOP15mo ago
Like a template?
Chioma
ChiomaOP15mo ago
No description
Chioma
ChiomaOP15mo ago
I always do github so not sure what to click from template
Brody
Brody15mo ago
at the bottom
No description
Brody
Brody15mo ago
your screenshot was cut off
Chioma
ChiomaOP15mo ago
okay clicked empty project what do you want a screenshot of the settings?
Brody
Brody15mo ago
well i wanted the screenshot so i could know what you had going on, but i know whats going on in an empty project now add a new empty service
Chioma
ChiomaOP15mo ago
okay! which one
Brody
Brody15mo ago
wdym? empty service
Brody
Brody15mo ago
No description
Chioma
ChiomaOP15mo ago
my b. added
Brody
Brody15mo ago
now give the project a name, and give the service a backend name
Chioma
ChiomaOP15mo ago
named my service. dont see where to name the project. does that not happen when i link the github..it doesnt take the name of the repo?
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
No description
Chioma
ChiomaOP15mo ago
okay got them named. thank ya
Brody
Brody15mo ago
go to atlas and regen your credentials since you have leaked them
Chioma
ChiomaOP15mo ago
it's okay. i made the credential specifically for this portfolio and it isn't any data i am worried about it
Brody
Brody15mo ago
we do things properly here 🙂 please regen your credentials
Chioma
ChiomaOP15mo ago
i like the name i gave it though. i want to keep it
Brody
Brody15mo ago
wdym name? anyone can connect to this database and put in or delete data
Chioma
ChiomaOP15mo ago
youre saying how my password is exposed on the link route?
Brody
Brody15mo ago
yes, its a nice password, but passwords should not be public
Chioma
ChiomaOP15mo ago
haha i understand i want to keep my password. i'll hide it as youre suggesting
Brody
Brody15mo ago
but its already out there
Chioma
ChiomaOP15mo ago
that's okay no one is looking at this and the database is just for a contact form
Brody
Brody15mo ago
there are hundreds of bots that scan public repos for credentials just like this, i know you like the password, but please change it trust me please when you have the new URL with the new password, add a service variable MONGO_URL with your new mongo URL
Chioma
ChiomaOP15mo ago
here?
No description
Brody
Brody15mo ago
not quite
No description
Chioma
ChiomaOP15mo ago
okay it's added. do i delete the one in my code now?
Brody
Brody15mo ago
can i see a screenshot of the service variable? (keep it hidden)
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
it should be named MONGO_URL
Chioma
ChiomaOP15mo ago
you did say that..my mistake - adjusted now
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
and that is the same url, just with a different password?
Chioma
ChiomaOP15mo ago
from atlas yeah
Brody
Brody15mo ago
alright ill trust you replace the url string with process.env.MONGO_URL https://github.com/ChiomaGrace/MyPortfolio/blob/master/backend/server.js#L9
Chioma
ChiomaOP15mo ago
done
Brody
Brody15mo ago
unquote that please https://github.com/ChiomaGrace/MyPortfolio/blob/master/backend/server.js#L9 otherwise monngo db url from atlas can go there for local testing haha no it cant, this will stay process.env.MONGO_URL forever
Chioma
ChiomaOP15mo ago
oh haha thank you for correcting
Brody
Brody15mo ago
do you have the railway cli installed?
Chioma
ChiomaOP15mo ago
i dont think so
Brody
Brody15mo ago
go ahead and do that https://docs.railway.app/develop/cli#installation this isnt needed for your deployment to railway, but its now needed to continue developing locally, since we put that mogo url in railway we need a way to use it when running locally too, and the cli can do just that
Chioma
ChiomaOP15mo ago
okay! before i run the railway link command i wanted to ask you about this
Chioma
ChiomaOP15mo ago
No description
Chioma
ChiomaOP15mo ago
it says access denied even though the web page that populated said success should i ignore and continue?
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
what does railway whoami say?
Chioma
ChiomaOP15mo ago
unauthorized. i switched to an adminstrator command terminal and all is well now link my portfolio?
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
yes
Chioma
ChiomaOP15mo ago
asking for me to select an environment now
Brody
Brody15mo ago
prod
Chioma
ChiomaOP15mo ago
okay did that
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
i think it would be a good idea to replace the text "service" with "backend" in your service name (in railway)
Chioma
ChiomaOP15mo ago
👍
No description
Brody
Brody15mo ago
railway service
Chioma
ChiomaOP15mo ago
sorry? oh run the command?
Brody
Brody15mo ago
yeah
Chioma
ChiomaOP15mo ago
okay done
Brody
Brody15mo ago
railway run npm run start
run Run a local command using variables from the active environment
run Run a local command using variables from the active environment
Chioma
ChiomaOP15mo ago
it is running succesfully
Brody
Brody15mo ago
awsome see now you keep the mongo url safe in railway
Chioma
ChiomaOP15mo ago
yeah! thank you. i can see how that is a better and safer route
Brody
Brody15mo ago
as long as you did change the password
Chioma
ChiomaOP15mo ago
can i link github now? or more to do
Brody
Brody15mo ago
two more things, generate the domain, and set the root directory to /backend both of these are in the service settings
Chioma
ChiomaOP15mo ago
also i forgot to mention which i think is expected? the server runs but my app isnt showing
Brody
Brody15mo ago
good reminder that is expected, yes, since this is just the backend delete this line please https://github.com/ChiomaGrace/MyPortfolio/blob/master/backend/server.js#L23
this connects/serves static files locally not needed for deployment
this connects/serves static files locally not needed for deployment
not needed for local either
Chioma
ChiomaOP15mo ago
oh really? my app didnt work when i didnt have that line locally
Brody
Brody15mo ago
i know, but going forward you will open up another vscode instance in the frontend folder and run npm run dev to run your angular app for local development
Chioma
ChiomaOP15mo ago
done and done
No description
No description
Brody
Brody15mo ago
connect repo time
Brody
Brody15mo ago
do you have postman or similar?
Chioma
ChiomaOP15mo ago
no i was using mongodb compass to see if my form was working
Brody
Brody15mo ago
you may want to have something like postman or insomnia to test the backend without using the frontend
Chioma
ChiomaOP15mo ago
okay! i'll look into it sorry this is another dumb question but how do i link my repo? since we did it from an empty project. sorry. ive always just clicked the deploy repo option the other times
Brody
Brody15mo ago
No description
Chioma
ChiomaOP15mo ago
thanks! okay it deploy succesfully but it isnt showing my app
Brody
Brody15mo ago
thats expected, this is just the backend so test the backend out (this is what postman would be for)
Chioma
ChiomaOP15mo ago
oh okay. that would make sense why the domain isnt what i changed it to okay i made a postman account. not too familar w this so how am i testing ?
Brody
Brody15mo ago
tricky question at a high level, you put your domain in and make api requests to it
Chioma
ChiomaOP15mo ago
and thats what you want me to do now right
Brody
Brody15mo ago
gotta confirm your backend is operational somehow right
Chioma
ChiomaOP15mo ago
yup yup so am i creating a worksapce or selecting datadog api collection?
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
honestly i don't know what any of that crap is for, I just use the desktop app
Chioma
ChiomaOP15mo ago
haha okay i'll download that real quick
Brody
Brody15mo ago
No description
Brody
Brody15mo ago
this is what postman does, makes calls the your api and shows you the results
Chioma
ChiomaOP15mo ago
ive seen it before in tutorials ive watched! i just havent used it or know how to make it shake
Chioma
ChiomaOP15mo ago
looks like the desktop has the same display
No description
Brody
Brody15mo ago
postman is supposed to be helpful, why they got the welcome screen looking so complicated workspaces > you may or may not see a my workspace, if you do click it, if you don't make a new workspace
Chioma
ChiomaOP15mo ago
clicked it! and here we are
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
little plus button, then start making api calls to your new backend you may want to watch some tutorials for postman? since a postman tutorial is a bit out of scope here
Chioma
ChiomaOP15mo ago
cant i get my front end to work and then just use mongodb?
Brody
Brody15mo ago
sure, why not, frontend time now!! so make sure you can run the frontend locally npm run dev
Chioma
ChiomaOP15mo ago
Error: Cannot find module 'C:\Users\chioma.ubogagu.SV-NB-DEV-78\node_modules\@angular\cli\bin\ng.js' run this right? npm install -g @angular/cli
Brody
Brody15mo ago
first off, we are now working on the frontend, this means you need to have a vscode window open in the frontend folder
Chioma
ChiomaOP15mo ago
i am there:)
Brody
Brody15mo ago
delete your node_modules folder
Chioma
ChiomaOP15mo ago
deleted
Brody
Brody15mo ago
npm install
Chioma
ChiomaOP15mo ago
done
Brody
Brody15mo ago
does npm run dev work now?
Chioma
ChiomaOP15mo ago
no:/ same error
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
what does that even mean lol
Chioma
ChiomaOP15mo ago
no idea haha i uninstalled and tried again same error
Brody
Brody15mo ago
add this to your devDependencies
"@angular/cli": "~16.1.8",
"@angular/compiler-cli": "^16.1.8",
"@angular/cli": "~16.1.8",
"@angular/compiler-cli": "^16.1.8",
and then do npm install and npm run dev again
Chioma
ChiomaOP15mo ago
woo! now it's working on angular sever localhsot 4200
Brody
Brody15mo ago
okay sounds good add a blank railway service to the same project that has the backend name it with an appropriate frontend related name set the root directory to /frontend
Chioma
ChiomaOP15mo ago
okay. like so?
No description
No description
Brody
Brody15mo ago
yep you know service names can have spaces and capitals to make the names look more presentable?
Chioma
ChiomaOP15mo ago
okay! should i change both?
Brody
Brody15mo ago
if you'd like to, all that really matters is that they have names to differentiate between the two service types
Chioma
ChiomaOP15mo ago
updated! do i connect the repo on the front end now?
Brody
Brody15mo ago
generate a domain I should have caught this sooner, but you want the backend to have a backend specific domain name
Chioma
ChiomaOP15mo ago
yeah i was just about to ask
Brody
Brody15mo ago
however you can give the frontend a nice and clean name, it doesn't have to say frontend in it
Chioma
ChiomaOP15mo ago
i need to change mine cause the front end one is the one that'll be the actual web browsing url right?
Brody
Brody15mo ago
right! see, you're catching on!
Chioma
ChiomaOP15mo ago
haha thanks. i have a GREAT teacher 😀 okay i changed the domain and the root directoy on the front end is going to the backend
Brody
Brody15mo ago
frontend is going to the backend?
Chioma
ChiomaOP15mo ago
yeah is that wrong?
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
the frontend service should have the root directory set to /frontend
Chioma
ChiomaOP15mo ago
understood..i adjusted now
Brody
Brody15mo ago
okay I think it's time you add the repo
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
send the full build logs please https://bookmarklets.up.railway.app/log-downloader/ also I think you haven't pushed your changes to your repo from when we fixed running angular locally
Chioma
ChiomaOP15mo ago
ah youre right i committed them deployed it deploy! but it doesnt show my app haha s'closeee
Brody
Brody15mo ago
it's not setup to make requests to the backend railway domain let me google how to do that real quick
Chioma
ChiomaOP15mo ago
thanks so much i'll try to have a look too
Brody
Brody15mo ago
there is a specfic way to do it that makes the dx much easier, i know how to do it for something built with vite but i dont know how to do it with angular yet okay lets get the railway side of this done
Brody
Brody15mo ago
add a service variable BACKEND_URL ${{My Portfolio(Backend).RAILWAY_PUBLIC_DOMAIN}} to your frontend
Chioma
ChiomaOP15mo ago
added! it's working!!
Brody
Brody15mo ago
huh nah
Brody
Brody15mo ago
what is working? can you send the frontend domain?
Brody
Brody15mo ago
what would be a page that makes a request to the express api?
Chioma
ChiomaOP15mo ago
that fails
Brody
Brody15mo ago
yeah thats what where gonna fix but first can you link me to a page that does make a request to the backend?
Brody
Brody15mo ago
theres no requests there?
No description
Chioma
ChiomaOP15mo ago
it's a form that's the only thing i use express for used* in this app
Brody
Brody15mo ago
ah okay i see now now have a look at this page, this is how we will tell your angular app to make requets to the railway backend domain when on railway, and to make requests to the locally running express app when running locally https://www.digitalocean.com/community/tutorials/angular-environment-variables#adding-development-and-production-variables
// src/environment/environment.ts
export const environment = {
production: false,
backendURL: 'http://127.0.0.1:3000'
};
// src/environment/environment.ts
export const environment = {
production: false,
backendURL: 'http://127.0.0.1:3000'
};
// src/environment/environment.prod.ts
export const environment = {
production: true,
backendURL: process.env.BACKEND_URL
};
// src/environment/environment.prod.ts
export const environment = {
production: true,
backendURL: process.env.BACKEND_URL
};
and then in whatever file you call /sendEmail you need to import environment
import { environment } from '../environments/environment';
import { environment } from '../environments/environment';
and then call environment.backendURL + '/sendEmail' instead i think, like i said i havent done this in angular yet
Chioma
ChiomaOP15mo ago
okay i think i have added everything, but my main.ts doesnt like the changes
Brody
Brody15mo ago
I don't do typescript lol so I'm not much help in that regard
Chioma
ChiomaOP15mo ago
ah okay
Brody
Brody15mo ago
make the ts compiler happy is about all I can say
Chioma
ChiomaOP15mo ago
haha okay one sec okay i think ive made everything happy
Brody
Brody15mo ago
have you swapped your backend calls to use the backendURL in the environment file?
Chioma
ChiomaOP15mo ago
yee
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
looks good change this build script to ng build --configuration=production https://github.com/ChiomaGrace/MyPortfolio/blob/master/frontend/package.json#L7
Chioma
ChiomaOP15mo ago
done
Brody
Brody15mo ago
push the changes and see what happens
Chioma
ChiomaOP15mo ago
still a no go one thing that is different the code you told me to put here: src/environment/environment.prod.ts export const environment = { production: true, backendURL: process.env.BACKEND_URL }; the code editor suggested/changed it to this
Chioma
ChiomaOP15mo ago
syntax
No description
Brody
Brody15mo ago
that should do the same thing the frontend is still trying to make a request to https://chioma-grace-portfolio.up.railway.app/sendEmail
Chioma
ChiomaOP15mo ago
yes i noticed that another thing i notced is im not seeing this console log when i run npm run dev
Chioma
ChiomaOP15mo ago
yes. sorry was trying to get a screenshot but youre fast haha but yes that one
Brody
Brody15mo ago
im stumped
Chioma
ChiomaOP15mo ago
i'll poke around but i have a question about working locally before i had two terminals running one would watch my angular (ng buld --watch) and then the other id run node(nodemon sevrer.js) now that it is configured for deployment..when i run npm run dev do i need to do something similar? cause right now i only see my angular locally when i run npm run dev how do i see my backend consle logs running that?
Brody
Brody15mo ago
you'd have two vscode windows open in the frontend and backend folder, and in the frontends terminal you'd run npm run dev and in the backends terminal you'd run railway run nodemon server.js of course you could set a dev script for your backend to nodemon server.js and then do railway run npm run dev for the backend and this environment.ts stuff was supposed to tell angular to call the locally running backend during development and call the backend running on railway when on railway without you having to switch over anything manually, but something isn't right with that part at the moment and it's now 4am for me, so I'm gonna head to bed, send me any updates though!
Chioma
ChiomaOP15mo ago
i was thinking the same. brody thanks sooo much for the help. that was so incredibly nice of you i saw on your profile i can buy a coffee for ya, and i am definitely going to do that. i just really need some sleep first ha. this chat i can come back to and reference right?
Brody
Brody15mo ago
absolutely, and if you really insist on buying the coffee, at least wait until we have this up and running lol
Chioma
ChiomaOP15mo ago
haha okay deal. good night! Hey Brody! I just wanted to touch base . Today's my birthday so I'll be out, but when I have time to tackle this again (hopefully tomorrow)! I'll jump back in this chat. I just wanted to let you know:)
Brody
Brody15mo ago
sounds good! happy birthday!
Chioma
ChiomaOP15mo ago
Thank you! are you free to look at it a little more this evening?
Brody
Brody15mo ago
Chioma
ChiomaOP15mo ago
oh nice! me too thank u
Brody
Brody15mo ago
dont do too much, i dont want there to be merge conflicts lol
Chioma
ChiomaOP15mo ago
ah okay sounds good finding anything helpful?
Brody
Brody15mo ago
im close angular is strange
Chioma
ChiomaOP15mo ago
it is a tricky one
Brody
Brody15mo ago
is it too late to switch to vite + vue
Chioma
ChiomaOP15mo ago
yeah but my next project i am switching
Brody
Brody15mo ago
awsome great news
Brody
Brody15mo ago
No description
Chioma
ChiomaOP15mo ago
wow!! you got it
Brody
Brody15mo ago
okay so in your frontend and backend services go and disable the triggers
No description
Chioma
ChiomaOP15mo ago
okay where is that option in settings? i dont see it
Brody
Brody15mo ago
right at the top
No description
Chioma
ChiomaOP15mo ago
okay they're both disabled
Brody
Brody15mo ago
in the backends service variables add a variable
FRONTEND_ORIGIN=https://${{<frontend service name>.RAILWAY_PUBLIC_DOMAIN}}
FRONTEND_ORIGIN=https://${{<frontend service name>.RAILWAY_PUBLIC_DOMAIN}}
Chioma
ChiomaOP15mo ago
like this right?
No description
Brody
Brody15mo ago
yeah but replace the <blah blah> with what it says to replace it with
Chioma
ChiomaOP15mo ago
okay mine was called backend url i replaced it now
Brody
Brody15mo ago
screenshot please
Chioma
ChiomaOP15mo ago
No description
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
not quite delete the frontends variables and set this on the backend
FRONTEND_ORIGIN=https://${{My Portfolio(Frontend).RAILWAY_PUBLIC_DOMAIN}}
FRONTEND_ORIGIN=https://${{My Portfolio(Frontend).RAILWAY_PUBLIC_DOMAIN}}
Chioma
ChiomaOP15mo ago
okay! good now?
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
yep
Chioma
ChiomaOP15mo ago
i deleted the front end variable too
Brody
Brody15mo ago
for future reference <frontend service name> this is a service name
No description
Brody
Brody15mo ago
set a frontend service variable
NG_APP_BACKEND_URL=https://${{<backend service name>.RAILWAY_PUBLIC_DOMAIN}}
NG_APP_BACKEND_URL=https://${{<backend service name>.RAILWAY_PUBLIC_DOMAIN}}
Chioma
ChiomaOP15mo ago
like so right?
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
yep now i make a pr to your repo with the fixes
Chioma
ChiomaOP15mo ago
what's a pr? like an edit?
Brody
Brody15mo ago
pull request where you update your repo with everything i did to fix it okay so look over the changes and ask me about anything you are unsure about or just wanna know more about, once you are happy you can merge it https://github.com/ChiomaGrace/MyPortfolio/pull/2
Chioma
ChiomaOP15mo ago
if i want to work on it locally can i still do so if you removed the app.use in the server?
Brody
Brody15mo ago
yes you can, we talked about this before, see this message
Chioma
ChiomaOP15mo ago
i know but when i tried it wasnt showing me the app. the sever was running but it wasnt displaying anything
Chioma
ChiomaOP15mo ago
like this
No description
Brody
Brody15mo ago
haha thats normal, you have no route for /
Brody
Brody15mo ago
once you run npm run dev in your frontend you get this, you then go to this url and you get your angular app
No description
Brody
Brody15mo ago
No description
Chioma
ChiomaOP15mo ago
i am a bit confused with that if i run on 4200 the back end wouldnt work on that localhost right? so thats why i was trying to see my app on 3000
Brody
Brody15mo ago
we talked about that too
Brody
Brody15mo ago
so see how you set this variable in railway? this is so your frontend knows what to call for the contact form, but locally you run railway run npm run start so your backend runs on https://localhost:3000 and this file will tell your locally running frontend app to make requests to your locally running backend
No description
Brody
Brody15mo ago
i tested this all out, both locally and on railway, it just works without any fuss, trust me
Chioma
ChiomaOP15mo ago
okay thanks for explaining~ !*
Brody
Brody15mo ago
do you need clarification on anything?
Chioma
ChiomaOP15mo ago
no i think i am okay! i have seen a lot about cors but didnt know how to implement
Brody
Brody15mo ago
i did that for you!
Chioma
ChiomaOP15mo ago
yes i saw!! thanks so much
Brody
Brody15mo ago
its rudimentary, but its there and it works lol
Chioma
ChiomaOP15mo ago
haha hey that's all that is needed
Brody
Brody15mo ago
so are you sure you still wanna use the database on atlas?
Chioma
ChiomaOP15mo ago
yup!
Brody
Brody15mo ago
thats totally fine, im just curious, why use it over a mongo database from railway?
Chioma
ChiomaOP15mo ago
no reason really. you think i should change to that? i just dont want to stay up too late is the thing
Brody
Brody15mo ago
nope just wondering so if you dont have any more questions about the pr, feel free to merge it
Chioma
ChiomaOP15mo ago
okay let me do that now
Brody
Brody15mo ago
after the pr has been merged, you can connect the branch back to the services
Brody
Brody15mo ago
No description
Chioma
ChiomaOP15mo ago
okay.
Chioma
ChiomaOP15mo ago
it crashed on me. should i just restart it as it's suggesting?
No description
Brody
Brody15mo ago
show me the logs please
Chioma
ChiomaOP15mo ago
it doesn't have any
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
click the red
Chioma
ChiomaOP15mo ago
ah i see the errow now
Chioma
ChiomaOP15mo ago
No description
Chioma
ChiomaOP15mo ago
but i removed that from code... i also merged your pr so shouldnt it be going off that as well
Brody
Brody15mo ago
i removed that redeploy yeah it doesnt exist https://github.com/ChiomaGrace/MyPortfolio/blob/master/backend/server/config/routes.js do a redeploy
Chioma
ChiomaOP15mo ago
okay i redployed. it went succesfully! i tested my form though and it still doesn't post successfully
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
can you send me each domain for those two services
Chioma
ChiomaOP15mo ago
yes does this mean the pr didnt go correctly?
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
thats my repo, thats normal domains please
Chioma
ChiomaOP15mo ago
it redeployed then went back to the old changes so weird here are the domains:
Brody
Brody15mo ago
yes they are using old code
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
remove the repo from both services entirely
No description
Brody
Brody15mo ago
then add it back
Chioma
ChiomaOP15mo ago
okay i did it it didnt work still, but it is using the right code at least should i change to the railway mongodb and see if it works w that?
Brody
Brody15mo ago
no thats not it this variable is wrong you set it to frontend please update it
NG_APP_BACKEND_URL=https://${{<backend service name>.RAILWAY_PUBLIC_DOMAIN}}
NG_APP_BACKEND_URL=https://${{<backend service name>.RAILWAY_PUBLIC_DOMAIN}}
Chioma
ChiomaOP15mo ago
No description
Chioma
ChiomaOP15mo ago
My service name is showing but still erroring out
Brody
Brody15mo ago
screenshot of the NG_APP_BACKEND_URL please
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
looks fine, do you have any trailing or leading whitespace?
Chioma
ChiomaOP15mo ago
no is the space an issue between my and portfolio?
Brody
Brody15mo ago
okay can you please remove the ()
Brody
Brody15mo ago
name your services how i have them
No description
Chioma
ChiomaOP15mo ago
that was it. it's working!! YOU ARE AMAZING!! i think i want to do what you said use the railway mongo db. that's just getting the link from there right? here:
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
nope so delete the current mongo variable from the backend, then add it back, railway auto completes it
Chioma
ChiomaOP15mo ago
really!? so cool let me try it
Brody
Brody15mo ago
also you just leaked your db again
Brody
Brody15mo ago
please go and reset
No description
Chioma
ChiomaOP15mo ago
reset or delete it first?
Brody
Brody15mo ago
reset it
Chioma
ChiomaOP15mo ago
okay it is reset now i delete the mongo url variable right?
Brody
Brody15mo ago
yep and replace it with the autofilled one
Brody
Brody15mo ago
No description
Chioma
ChiomaOP15mo ago
got it!
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
just as a sanity check, show me the mongo variable in the backend?
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
perfect
Chioma
ChiomaOP15mo ago
i need to get my local to have your changes now right? last thing to do is that a github fork
Brody
Brody15mo ago
just pull the repo
Chioma
ChiomaOP15mo ago
oh yeah duh. okay i think i'm all good you are a saint. thanks sooo much for your time
Brody
Brody15mo ago
no problem 🙂
Chioma
ChiomaOP15mo ago
oh one weird thing i am seeing
Brody
Brody15mo ago
yeah?
Chioma
ChiomaOP15mo ago
No description
Chioma
ChiomaOP15mo ago
No description
Chioma
ChiomaOP15mo ago
do i need to do a npm install?
Brody
Brody15mo ago
yep beat me to it youd need to do an npm install in both frontend and backend, might even be good to delete the node modules folder and then rerun that command
Chioma
ChiomaOP15mo ago
okay my comp is doing a stupid you need to be admin even though i am it does this time to time one sec
Brody
Brody15mo ago
yeah that's very odd, I haven't gotten any of those kinds of errors before
Chioma
ChiomaOP15mo ago
it's something IT did to my work computer, and it's been giving me problems for awhile now. super annoying but anyway thank you so much!! it looks like i'll have to ask them to do something for the admin thing so i can delete and install the package but looks like it's all good to go besides that!!
Brody
Brody15mo ago
i agree, think id just reset the computer at that point if it happened to me lol awsome!
Chioma
ChiomaOP15mo ago
heading to bed but will def purchase a coffee for you tom!! really really appreciaive of your time
Brody
Brody15mo ago
thank you 🙂
Chioma
ChiomaOP15mo ago
okay finally deleted the node modules and ran npm install so now i just use railway run npm start right?
Brody
Brody15mo ago
for your backend, yeah the frontend doesn't need to be ran with the railway cli
Chioma
ChiomaOP15mo ago
front end still ng build --watch ?
Brody
Brody15mo ago
that's just npm run dev
Chioma
ChiomaOP15mo ago
right sorry. it's just very different so trying to grasp. before everything would work on localhost 3000 and i could see my angular through that cause of app.use that was calling my dist folder i dont understand how this is working fully
Brody
Brody15mo ago
angular is running its own server for you
Chioma
ChiomaOP15mo ago
and the form should work on it still?
Brody
Brody15mo ago
as long as you have the backend running in a separate vscode window, yep! it should all just work
Chioma
ChiomaOP15mo ago
this is what i have i think it is working but issue w monogoose this cause i changed the url?
Brody
Brody15mo ago
I had no issues locally, what issues do you have?
Chioma
ChiomaOP15mo ago
i failed my form on purpose to see if my validations are working the deployed verision it works great
Chioma
ChiomaOP15mo ago
No description
Chioma
ChiomaOP15mo ago
locally it is doing this
Brody
Brody15mo ago
I saw those on railway too
Chioma
ChiomaOP15mo ago
No description
Brody
Brody15mo ago
just simple code issues this is my first time doing anything with angular, so what I've already done is about where my knowledge on the subject of angular runs out unfortunately
Chioma
ChiomaOP15mo ago
i hear ya! i will poke at it. it's just weird cause it worked before deployment, works in deployment, but then now locally it is acting up i might leave it honestly. i just need to make a few styling adjustments in some places
Brody
Brody15mo ago
if that's good with you then thats great, it is just some code issues, I'm sure you would be able to get them ironed out
Chioma
ChiomaOP15mo ago
youre right it was a quick fix haha okay thank you thank you thank! i'll check back in tom to make sure you got the coffee payment thingy. do i close this ticket now?
Brody
Brody15mo ago
I have marked this thread as solved, nothing you need to do 🙂
Want results from more Discord servers?
Add your server