Loki Astari
Loki Astari

Reputation: 264391

Nodejs server configuration experimentation

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.

Upvotes: 0

Views: 189

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146014

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.

Upvotes: 2

Related Questions