Sunday, 7 February 2016

Stumped on where to go with Node + Nginx + Github Auto-deploy.

Hello r/node! In a sentence I am trying to learn how to setup: Ubuntu, Node, Nginx, MongoDB, SSL and Auto-deploy from Github on a Digital Ocean droplet.What I have so far:SSL but not currently working; giving me 403 Forbidden status codeNginx reverse proxy to nodeOne node server serving up static files created by metalsmithNo DBNo testsGithub webhook 'Post' to a url that uses child_process.spawn to run a shell scriptScript runs git pull, gulp to build Sass and metalsmith, restarts nginx and restarts 'forever' running my node serverThe way this is set up seems to me to be very hacky as currently I am only looking at the request header to see if it from guthub and that 'post' was the command that was sent.What I am trying to create:SSL with LetsEncryptNginx serverSits in front of the node servers and reverse proxy to the front-end node serverHandles static filesFront-end node serverRenders public viewsRenders admin viewsUser API node serverHandles user auth and sessionHandles user CRUDRenders JSONBlog API node serverHandles Blog CRUDRenders JSONPortfolio API node serverHandles Portfolio CRUDRenders JSONMongoDB with the native node driverModel/Controller testsUse Github webhooks to manage push-to-deployA little background and my Issues so far:Besides the SSL issue (haven't had the time to really look into it so I don't have a clue on this one) I am wondering if this is a viable setup. I am building an extremely small CMS for my personal site. The only content that I will have is Blog posts and Portfolio pieces.I currently have an incomplete skeleton of my plan on my site at pburris.me. Remember that is no where near a complete site, so please don't judge too harshly.I was able to setup Nginx and reverse proxy to node quite easily following this DigitalOcean guide. It wasn't until a couple days later that I first read that nginx is WAY better for static files than node and I kept reading that almost everytime I read about nginx + node.Why is nginx better for static files than node?I plan on building out node apps for the blog, portfolio and user system, then call those apis in my main 'front-end' node server that actually renders my views. I am thinking this is a good route to go for scalability (not that I plan on this site blowing up, I just want to learn the best ways of dealing with scalability early on). I also feel like I will be copying a lot of code between the Blog and Portfolio servers when it comes to CRUD interactions with my DB, how should I mitigate this and keep my code base DRY?Should I really have 4 node servers running?Right now I am (in my opinion) running a sketchy auto-deploy. When I push to my repo on github it uses the 'post' webhook pointed at a url on my site. This is from an example I found on Github that I modified:if (req.headers['x-github-event'] != 'push') return res.status(200).end(); var command = spawn(__dirname + '/build.sh'); var output = []; command.stdout.on('data', (chunk) => { output.push(chunk); }); command.on('close', function(code) { if (code === 0) res.send(Buffer.concat(output)); else res.send(500); }); Is this as sketchy as I feel it is?I have seen a few modules that help with Github Webhooks, but I didn't know which one was best (most I have looked at are out of date), so I just went with the minimum viable code to get the results that I wanted, now I want to make sure I can secure it, which means I need to get a deeper understanding of root, chmod, chown and sudo than I currently have. I also need to strengthen my bash scripting skillsClosing questions -- Am I headed in the right direction? Any advice for someone trying to hone their Backend/Sysadmin skills? What are some common pitfalls I should look out for as attempt to go from what I have to what I want?Thank you Reddit!

Submitted February 07, 2016 at 04:09PM by Jumballaya

No comments:

Post a Comment