Skip to content

floatrx/mern-blog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mongoose-express with client app (React)

A simple express server with mongoose (ODM) with typescript and a client app (Vite/React) to manage the blog posts and other data. Demo https://blog.floatrx.net/

Note

The main goal is to demonstrate how MongoDB works with Express server in Node.js, using the Mongoose ODM. I created a simple client-side part for demonstration purposes. For a search engine-friendly blog, it's best to go with Next.js.

blog

MdxEditor (client)

blog

Pre-requisites

Database: MongoDB

Check the mongodb README for more information.

Client & Server

Check the client and server READMEs for more information.

Development

yarn dev

Note

Mount the mongo container before running the server.

Roadmap

  • OAuth2 (GitHub)
  • find post by author tag
  • paginate posts
  • find posts by tag

Deployment

  1. Setup mongo with docker or use a cloud service
  2. Setup server with pm2 and nginx (check ecosystem.config.js for more information)
  3. Setup client with nginx

Nginx (example configuration)

# API
server {
    server_name blog-api.floatrx.net;
    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
    error_log /var/log/nginx/blog-api-error.log;
}
# CLIENT
server {
    server_name blog.floatrx.net;
    root /var/www/blog;
    index index.html;
    location / {
        try_files $uri $uri/ /index.html;
    }
}

Note

Use certbot to generate SSL certificates.

Happy coding! 🚀