9 ms·
Show HN: Deploying subdomain-based routing like github.io
- dygd 3y agoIn addition to CLI params and JSON conf it would be handy to support env var configuration. Makes running inside a container much easier.
- spoiler 3y agoWould it make it much easier? If you really need env var support, you can just wrap this, I suppose. But more conveniently, you can also mount (and load from a config map in the context of kubernetes).
- dygd 3y agoYes, I think that env vars are superior to a file or CLI args. One advantage is that you can pass secrets without persisting in a file or making them visible to other processes through CLI args.
- oasisaimlessly 3y agoEnv vars are visible in /proc/PID/environ, though? That said, the mode on environ seems to be 600 on my system, so only processes with the same UID can see them.
- robertlagrant 3y agoDoes that mean you're restarting your nodes after every change? It'll work, but mightn't it be a bit tricky if lots of people start creating tenants? Edit: actually, based on the use case cited in the readme, this would be fine. I was thinking more of a website like GitHub that lets people sign up and create tenants.
- defanor 3y agoPossibly I am missing something, but is it different from, say, nginx's `root /var/www/$http_host`? The description sounds as if a whole web server is written for that feature.
- deleted 3y ago[deleted]
- rlex 3y agoyeah, it can be done entirely on nginx side in like 10 lines.
- jatins 3y agoWhile your comment is valid, there's a whole generation of developers (me included) who are more aware of Node ecosystem than Nginx.
- panki27 3y agoThese are not even remotely comparable. nginx is a webserver.
- k_roy 3y agoha, 1) nginx is a webserver not a development ecosystem, and 2) You'll probably find if you look that many people using Node are also using nginx, because they are complementary, not exclusionary, and 3) open your eyes and reality a bit
- jatins 3y ago1/ what's a webserver? 2/ Is a node application serving requests not a webserver?
- pluc 3y agoThis is why I'll never hire a "full-stack developer".
- 3y ago
- VoidWhisperer 3y agoNot to detract from the work done here, but couldn't something very similar be accomplished via nginx vhosts or somethin similar in apache?
- deleted 3y ago[deleted]
- panki27 3y agoAs far as I can tell this is just a fancy costume on top of Server Name Indication. So yes, yes you could (and I'd do it like that).
- anacrolix 3y agoHow is it different from just reading the Host header and serving a directory based on that?
- alexdunmow 3y agoThis would be pretty easy in Go, too.
- thangngoc89 3y agoI think Node.js is unsuitable for normal routing tasks like this because of single-threaded runtime. This could be achieved really easily with popular web servers like nginx or caddy. If I remember correctly, there was a lot of tutorial about serving static files using nginx in front of express.js/koa.js for better performance and that serving static files doesn't compete with the dynamic part of the website.
- deleted 3y ago[deleted]
- inetknght 3y agoNeat. One big nitpick: I think this is solved better by other solutions. One small nitpick: why serve under /websites instead of under /srv? /srv is a standard [0] directory. [0]: https://en.wikipedia.org/wiki/Filesystem_hierarchy_standard https://en.wikipedia.org/wiki/Filesystem_hierarchy_standard
- onionisafruit 3y agoMaybe they keep all their Stevie Ray Vaughan bootlegs in /srv
- swozey 3y agoI spent 15 years in webhosting and I've literally never seen /srv used. MAYBE for sftp and I'm misremembering but I rarely had to deal with that. It's always /var/www/$url.
- k_roy 3y agoit's used, but not very often. tftp is one that is regularly served out of there. In reality, larger software projects like nginx and apache have their own opinions and usually serve out of different places.
- swozey 3y agoI've always loved that to do basic auth nginx has you make an apache2 directory and place your htpasswd in there as a best practice/recommended setup. And use apache-utils.. but I guess why reinvent the wheel. # auth_basic_user_file /etc/apache2/.htpasswd; https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/ https://docs.nginx.com/nginx/admin-guide/security-controls/c...
- k_roy 3y agoThis is probably more ancient documentation for switchers from Apache. The main reason for this is to make sure your htaccess file is outside of the document root. This is horrible behavior Apache had (still has?), and is a security issue.
- jedberg 3y agoA relevant sidenote: If you're going to do this, make sure you don't allow the content to also be accessible on the top level domain with a different URL, and that one redirects to the other. Two reasons for this: - Security: You want the cookies to be limited to the subdomain - SEO: You get penalized if the same content is available at two URLs, because it is assumed it's a copy The SEO issue applies in the other direction too. When we first set this up for reddit (you could and still can go to subreddit.reddit.com), we found out that we were getting penalized for having the same content on both URLs. So we set it up to redirect the subdomain to the /r/subreddit URL since that was the canonical URL and the cookies didn't matter.
- xyheme 3y agoThanks, I now learn double content s have this effect on SEO :)
- CableNinja 3y agoYou couldve accomplished this at the webserver level, with way less hassle, and better performance. One would be complex rewrite rules. Another, is to use LUA with Openresty. And you dont need another node app, and you dont need the terrible performance you get with the node app, and you dont use a language meant for frontend things to do backend things. Seriously, what is it with every node dev using node for everything???? Yes, i know when all you know is a hammer, everything is a nail, but seriously, come on. There are plenty of better languages to have done this in, all of which are more performant for this type of thing, had you still decided to not use lua/rewrites.
- davidlumley 3y ago> You couldve accomplished this at the webserver level That's true, but only if you have access to your web server! If you're using something like Vercel (or some other hosting service) to run your application, having a little middleware that handles subdomain routing is pretty common. edit: Sorry if I've read this comment out of context - the linked repo has been taken down.
- m90 3y agoMeta: Link currently 404s
- gbraad 3y agoProbably removed after feedback regarding the use of Node
- gsuuon 3y agoLooks like it's back! The ornery gatekeeper of true backend scowls while shaking their raised fist.
- xyheme 3y agoHi, it's you again :) My aim is to build a open-source mini vercel and netlify alternative. `x-server` is just a starting point. I have even more "evil" projects, like "using file system as database", I will leave that for another Show HN :) :) :)
- gsuuon 3y agoIt's always neat to see different ways of doing things! Keep at it :)
- xyheme 3y agoI enjoy the criticism, I think I can learn things from them. So far, feedback here are helpful to me. Sorry about the mis-deleting.
- xyheme 3y agoSorry about that, I was migrating my websites and repo out of vercel (to use this tool), during which I deleted a lot of outdated github repos. I thinks I accidently deleted this repo. Now it is back: https://github.com/xieyuheng/x-server https://github.com/xieyuheng/x-server
- alfanick 3y agoWhy node.js is involved? nginx, apache, any web server can do it itself since the beginning of an era.
- techn00 3y agoI made something similar for kubernetes a while ago https://github.com/DeluxeOwl/subdomain-mapper-operator https://github.com/DeluxeOwl/subdomain-mapper-operator
- fsniper 3y agoSmall nitpick about the naming. "X Server" term is used for an X window protocol server application. https://en.m.wikipedia.org/wiki/X_Window_System https://en.m.wikipedia.org/wiki/X_Window_System
- deleted 3y ago[deleted]
- TheHappyOddish 3y agoMan there is a lot of negativity here, some people really need to reread the guidelines. Good on you. As a sysadmin of decades I could absolutely to this in a few lines of nginx or other web servers as others have mentioned, however this looks like a cool and fun project. Just because doing it one way wins on some specific metrics (like performance) doesn't mean it does for other people (like node developers who want to change some server functionality). I can't believe people can write with a straight face that a web dev should learn nginx, set up openresty and write a lua script to do this. Get out of your own bubbles people.
- tamimio 3y agoI am a little confused, why not just create a CNAME and point it to that server?!