0

Setting up a nodejs server to serve the REST interface (with json objects) to my application. This works fine.

Currently I run Jekyll service to provide the content pages. This causes some cross site scripting issues as they are running on different ports. I can get around this but it does not seem like the optimal solution.

Is it normal to run a nodejs server to provide the REST interface and the web content interface on the same port. I have been looking at nodejs/express/Swig as a replacement for the Jekyll service but I it seems that running the express/Swig on nodejs will alter the behavior of my response objects that makes using REST not quite as optimal.

Alexander Solovets
  • 2,447
  • 15
  • 22
Martin York
  • 257,169
  • 86
  • 333
  • 562

1 Answers1

2

Is it normal to run a nodejs server to provide the REST interface and the web content interface on the same port

Yes, this is pretty common as it is much simpler to deal with, so many small apps/apis opt for this approach. Sometimes the API uses a URL path prefix like '/api' as a basic distinction. Sometimes folks use content negotiation where '/user/42' will send either HTML or JSON depending on the request `Accept' header.

However, it is also common to use a web server on port 80 that routes to different back end apps based on a path, so for example anything to /api would be reverse proxied to an express app on 127.0.0.1:3000 but everything else looking for content pages might go to a jekyll app on 127.0.0.1:3001.

  • How I would roll. Because I am very much in favor of using a real web server on port 80
    • nginx on port 80 reverse proxying to express for API and jekyll for content
  • Also possible
    • express listens on 80, handles API directly, uses node-http-proxy to reverse proxy content from the jekyll app
  • there are a bunch of other combinations you could make work easily. Mostly it's about what you think is easy to understand and is reliable, secure, etc.
Community
  • 1
  • 1
Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
  • So you are suggesting a standard web server on 80. Then content engine and REST engines on different ports, BUT the web server routes the requests to the appropriate ports. – Martin York Dec 10 '13 at 00:27
  • You can actually even do this directly with Node, using something like https://github.com/nodejitsu/node-http-proxy – brandonscript Dec 10 '13 at 00:58