Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use node.js as webserver #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

ameensol
Copy link

Hi Dave,

Great project! Really cool to see the NYT put a river on their home page, and now that they've done it everyone else probably will want to.

I've been wanting to play around with River4 for a while now, so I decided to give it a shot. I'm using a Digital Ocean droplet, so I wanted to see if I could use the River4.js script to also serve the index.html file, and with a few tweaks I was able to do.

In order to dynamically serve the user's river files, the server has to compare the pathname to each river file in the /rivers directory, and serve that file if there is a match. Since the pathname is going to be dynamic (/rivers/apple.js || /rivers/nytriver.js || /rivers/*.js), using a switch statement is difficult. The only way I could think of still using a switch statement was to use regex matching for the cases and then use switch(true). I thought this was overly complicated so I rewrote the router to use if/else statements.

The danger of relying on this setup is two-fold. First, it isn't likely to scale very well. The same process that is updating the feeds is also responsible for serving them. The process could get bogged down pretty easily if there was a lot of traffic.

If scale isn't an issue though, the other problem is that it introduces a single point of failure. If the node process crashes while updating a feed, users will no longer be able to access the site. On the other hand, if this script's role is simply to fetch feed updates and another server is responsible for serving the website, then if the node process crashes users will still be able to see the site, though a somewhat outdated version of it (depending on how long the node process stays down).

In any case, I don't expect to have either of the above issues on my personal river, since it's more for me than anyone else. I thought I'd share my code regardless, in case you find any of it helpful. I look forward to more of your hacks! I think you're on to something big here.

Amiably,
Ameen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant