Skip to content

A humble blog with live update feature. Server-rendered, rate-limited and tested.

Notifications You must be signed in to change notification settings

Marija-Kov/good-ol-blog-website

Repository files navigation

‼️📣ATTENTION: This app may take a couple of minutes to load due to the limitations of Render's Free web service. Thank you for your patience❣️


Client 1 receives live updates as Client 2 performs them


Table of Contents

  1. App Features and Limitations
  2. Local Usage
  3. Tools and Dependencies
  4. Environment variables
  5. Todos
  6. Author


App Features and Limitations

Index page shows a list of blogs/links. Scrolling down the page will send requests to the server and load more blogs in chunks.

Guest users have read-only access to blog posts, and other content on the website. This restriction is implemented by conditional rendering in the views that may show different content depending on the authenication status.

Immediately upon signing up, a user document is created in the database and the user can log in to their account and see authorized-user-only options.

Authorized users can (for the time limited by the validity of the session cookie) post and edit blogs. The user can log out manually or they will be logged out automatically when the cookie expires. Any attempts to perform authorized-user-only actions upon token expiration will be followed by redirection to the page with error message and automatic redirection to the index.

All users can enable live update feature and see all current blog and user activities.

Certain routes have been implemented with caching mechanisms.

Limitations

  • The number of users and blogs in the database is limited and each will be subjected to automatic deletion, oldest first, when the limit is reached;
  • Request rate limit has been set up and the server will respond with error and block client requests whenever the limit is reached;
  • Live update closes when navigating to a different page;

Local Usage

  • Clone repository;
  • Install dependencies - npm install ;
  • In the root directory, run: openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout key.pem -out cert.pem -subj "/CN=localhost" -days 365 to create self-signed security certificate to bypass strict policies of some browsers (like Chrome);
  • Run the development server - npm run dev ;
  • Run tests - npm run test;
  • IMPORTANT: you have to explicitly type https to open the app in your browser in dev mode, example: https://localhost:3002. This is necessary because in dev environment, https Node module is used to create the server.

Tools and Dependencies

Dev Dependencies


Environment variables

If you want to run the app in your local environment, you'll need to create a .env file in the root directory and provide values for the variables below.

MONGO_URI=
TEST_MONGO_URI=
SECRET=
HOST= #-- Should be https://localhost:{port_number} for live update to work under browser security restrictions
WSS_HOST= #-- Should be wss://localhost:{port_number}
TEST_PORT=
PORT=
DOMAIN=
PER_PAGE_LIMIT=
TEST_MAX_USERS_LIMIT=
TEST_MAX_BLOGS_LIMIT=
MAX_USERS_LIMIT=
MAX_BLOGS_LIMIT=

#Keep in mind the number of user and blog route tests when you're setting test rate limit.
MAX_API_USER_REQS=
TEST_MAX_API_USER_REQS=

API_USER_WINDOW_MS=
TEST_API_USER_WINDOW_MS=

MAX_API_BLOGS_REQS=
TEST_MAX_API_BLOGS_REQS=

API_BLOGS_WINDOW_MS=
TEST_API_BLOGS_WINDOW_MS=

Todos

  • The enabled state of the live update feature should, ideally, persist in between rendering of different pages;
  • Develop a solution to communicate free web service limits to users within the app;
  • Test live update feature;
  • Test client-side logic;
  • Blog chunks should be showing in consistent style. As is, the first chunk to load on scroll appears not to be animated;
  • Minify CSS;

Author

@marija-kov