How can I host my API and web app on the same domain?

corasan

I have a Rails API and a web app(using express), completely separate and independent from each other. What I want to know is, do I have to deploy them separately? If I do, how can I make it so that my api is in mysite.com/api and the web app in mysite.com/

I've seen many projects that do it that way, even have the api and the app in separate repos.

svens

Usually you don't expose such web applications directly to clients. Instead you use a proxy server, that forwards all incoming requests to the node or rails server.

nginx is a popular choice for that. The beginners guide even contains a very similar example to what you're trying to do.

You could achieve what you want with a config similar to this:

server {
    location /api/ {
        proxy_pass http://localhost:8000;
    }

    location / {
        proxy_pass http://localhost:3000;
    }
}

This is assuming your API runs locally on port 8000 and your express app on port 3000. Also this is not a full configuration file - this needs to be loaded in or added to the http block. Start with the default config of your distro.

When there are multiple location entries nginx chooses the most specific one. You could even add further entries, e.g. to serve static content.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to integrate wordpress blog into my rails web app at the same domain?

From Dev

How can I use my godaddy domain for my Django App

From Dev

How to deploy a Web API to my web host?

From Dev

How can I pass a moderately large volume of data to my Web API app?

From Dev

How can I dynamically create checkboxes based on query results in my Web API MVC app?

From Dev

How can I get my Web API app to run again after upgrading to MVC 5 and Web API 2?

From Dev

How can I get my Web API app to run again after upgrading to MVC 5 and Web API 2?

From Dev

Can I host in app engine for a domain purchased already

From Dev

How can I access my nodejs web server from my local computer using the server domain name?

From Dev

how to host customers domain on my server using cpanel api

From Java

How can I detect if my Flutter app is running in the web?

From Dev

How can I decrease zoom level in my web app?

From Dev

How can I disable Web Inspector for my BlackBerry App?

From Dev

How can I retrieve a list of changes for my Java web app?

From Dev

How can I include a port in my domain?

From Dev

How can I get my domain to do this?

From Dev

How can I host my own website

From Dev

How can I host my own website

From Dev

How I can Dockerize my web api on windows

From Dev

How can I have a wordpress page and a windows server web application under the same domain?

From Dev

How do I host a web application and an API from the same server while keeping them in separate?

From Dev

Can an MVC web app and an API web app run in the same pool?

From Dev

How can I filter by domain name within my Rails app in Heroku?

From Dev

Can I host laravel app and elasticsearch on the same vps?

From Dev

How can I see the domain name or ip of the PC accessing my API method?

From Dev

How do I separate my REST API from my Express web app?

From Dev

where can i host my spring rest api and databse

From Dev

How can I code my web app so that it knows what web server it's on?

From Dev

How can I display in my ExtJS web-app the sencha app build timestamp

Related Related

  1. 1

    How to integrate wordpress blog into my rails web app at the same domain?

  2. 2

    How can I use my godaddy domain for my Django App

  3. 3

    How to deploy a Web API to my web host?

  4. 4

    How can I pass a moderately large volume of data to my Web API app?

  5. 5

    How can I dynamically create checkboxes based on query results in my Web API MVC app?

  6. 6

    How can I get my Web API app to run again after upgrading to MVC 5 and Web API 2?

  7. 7

    How can I get my Web API app to run again after upgrading to MVC 5 and Web API 2?

  8. 8

    Can I host in app engine for a domain purchased already

  9. 9

    How can I access my nodejs web server from my local computer using the server domain name?

  10. 10

    how to host customers domain on my server using cpanel api

  11. 11

    How can I detect if my Flutter app is running in the web?

  12. 12

    How can I decrease zoom level in my web app?

  13. 13

    How can I disable Web Inspector for my BlackBerry App?

  14. 14

    How can I retrieve a list of changes for my Java web app?

  15. 15

    How can I include a port in my domain?

  16. 16

    How can I get my domain to do this?

  17. 17

    How can I host my own website

  18. 18

    How can I host my own website

  19. 19

    How I can Dockerize my web api on windows

  20. 20

    How can I have a wordpress page and a windows server web application under the same domain?

  21. 21

    How do I host a web application and an API from the same server while keeping them in separate?

  22. 22

    Can an MVC web app and an API web app run in the same pool?

  23. 23

    How can I filter by domain name within my Rails app in Heroku?

  24. 24

    Can I host laravel app and elasticsearch on the same vps?

  25. 25

    How can I see the domain name or ip of the PC accessing my API method?

  26. 26

    How do I separate my REST API from my Express web app?

  27. 27

    where can i host my spring rest api and databse

  28. 28

    How can I code my web app so that it knows what web server it's on?

  29. 29

    How can I display in my ExtJS web-app the sencha app build timestamp

HotTag

Archive