api - Separate back-end and front-end apps on same domain? -


we building restful back-end play framework. building separate web front-end different technology stack call restful api.

how deploy both apps have same domain name, url's used backend api , front-end views?

for example, visiting mydomain.com means front-end displays home page, sending mydomain.com/product/24 means back-end returns json object product information. further possibility if web browser views mydomain.com/product/24, front-end displays html page, , webpage built back-end call same url.

finally, need 2 dedicated servers this? or can front-end , back-end deployed on same server (e.g. openshift, heroku)

you gonna dig yourself... deep :)

simplest , clean approach no doubt creating single application serving data both, , fe, differ response (json vs html) url, pseudo routes:

get  /products/:id          controllers.frontend.producthtml(id)  /backend/products/:id  controllers.backend.productjson(id) 

benefits:

  • single deployment (let's heroku)
  • name space managed 1 app
  • no need modify models in many apps after change in 1 of them

else if

if you're determined create 2 separate apps, use http server proxy - example nginx - send requests domain.tld/* application working @ port 9000 (which answer html) requests domain.tld/backend/* redirect application working @ port 9001 responding json.

else

if gonna response json or html depending on caller can try compare headers check if request sent browser or ajax call in each controller , believe me become nightmare faster thing... insert coin, choose flavor


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -