Playground is a mini-CMS, where I host my websites. Techstack includes Nodejs, MongoDB, Handlebars and Pjax.
- CMS - Content Management System - Content is "data" and "modules". For example, "SendMail" module is written & maintained once, and it works for all the websites hosted on CMS. Now next time I am building a website, I do not need to
copy pastethe code. You just need to call this module, and it is available to you. Nice ;). - It is easier to work on a single project (this CMS is one project). Code doesn't go lost in the void. Before building it, everytime I wrote my million dollar idea, some days later it just goes lost in the
void. So, some actual workable ideas goes flat with that. - Do all of that in 6 USD Digital Ocean droplet (I started with this benefit in mind, but now realise there are other ways too to save money - humbled).
-
Simple HTML request: Provides a rendered website after fetching content from database. For example, https://7amuniforms.com request goes to the NGINX file, that expands this url to https://7amuniforms.com/7am/gen/page/landingPage/n and responds back with a website.
-
Ajax request: Provides only the data in JSON format when receiving an ajax request. For example, https://7amuniforms.com/7am/gen/data/landingPage/n gives back the JSON file. In case, you do not want the html and only JSON, you can replace the word "page" with "data" and it will respond back with just the data.
-
Pjax request: Provide Pjax (partial ajax) so that entire website is not loaded again when a filter is clicked somewhere. For example, https://7amuniforms.com/7am/gen/page/kallesShop/n?school=Allied%20School&type=uniform is a pjax request (yes, it has pjax word in the url). Also when you change the filter in the website, it will only reload the content, and not the entire page.
All requests reaching the server are formatted in following syntax;
app.get(
'/:brand/:permit/:requiredType/:module/:input',
replyFunction
);
:brandis a brand's unique key. The website unique key (for example 7am) in this url :- https://7amuniforms.com/7am/data/page/landingPage/n.:permitis the request authentication type. It has three types; gen, auth, admin. Gen is general level request. Auth is for owners of the website. And Admin is for the super admins.:requiredTypeis the type of request you are making to the website. It has three types also; page, data, and pjax. Page is when user wants the rendered website. Data is when user is looking only for the data (the JSON). and Pjax is when he is looking for a portion of the website.:moduleis the name of the module. For example, when sending mail, thesendMailmodule in the server is accessible. Just send theemail,mail text,email templateand it sends the email to website owner's email address (or ship a newsletters to many subscribers).:inputis the kind of input that you send to the module. For exampleshowBlogmodule takes theblog-slugas its input. Slug is a unique identifier for each blog post in the database.
replyFunctionthen constructs a webPage || a data object || a pjax page and returns the website to the client.
Leave a comment, some feedback, that you think can help me improve my code.