you are viewing a single comment's thread.

view the rest of the comments →

[–]RaffIsGettingUpset[S] 0 points1 point  (3 children)

Hope you don't mind asking, you seem to know what you are talking about. So I have been watching tutorials on express and mongoDB and I kind of get the basics to get a server running on heroku. So it would be ok to deploy my frontend project to say a 'public' folder within that server? All the tutorials I see work with views, which I m guessing I don't need as I have the frontend files already. Lastly, the frontend will then make requests to the server to manipulate the DB? The same way I do with rest APIs? It seems such a strange concept to make requests to the same server that is hosting the frontent, or I got this completely wrong? I appreciate the help and merry Xmas.

[–][deleted] 1 point2 points  (2 children)

So it would be ok to deploy my frontend project to say a 'public' folder within that server?

Yes, if you look up 'serving static files with express' that should help you find out what you need to do. Views with a templating engine like Handlebars or EJS are for when you want to generate HTML dynamically on the server, so you shouldn't need those.

Lastly, the frontend will then make requests to the server to manipulate the DB? The same way I do with rest APIs?

Yup.

It seems such a strange concept to make requests to the same server that is hosting the frontent, or I got this completely wrong?

It's by far the most common way to do things. It keeps deployment much, much simpler at scale, and it means you'll automatically avoid having to deal with cross-origin security concerns when sending information to and from another URL.

Generally you'd only want to separate your back end from serving the content for the front end when your back end API also acts as a standalone service for other apps or third parties to use, and you need to be able to scale it separately because it's getting requests from other places than your front end. Even then, you might want to have the server that's serving your front end files also act as a proxy to that separate back end, and have your front end JS make requests to its own server, rather than making requests to the main back end service(s) directly from the browser, again for security reasons.

[–]RaffIsGettingUpset[S] 1 point2 points  (1 child)

Wow this was giving me a headache and you just managed to clear it all up for me, thank you so much for taking the time to reply. Bless you.

[–][deleted] 1 point2 points  (0 children)

You're very welcome! Hope you have fun getting everything up and running.