Skip to content

robphilipp/recipes-ui

Repository files navigation

recipes

Basic recipe book for cooking great things.

contributing

The recipe book app uses mongodb to store the recipes. You'll want to set up or point to a mongo database.

setting up mongo db

On macOS with homebrew

Install mongodb

brew tap mongodb/brew
brew install [email protected]

Start mongodb with

brew services start [email protected]

Stop mongodb with

brew services stop [email protected]

This project uses migrate-mongo to set up the recipe collection in mongoDB and to migrate changes to the schema and data. To get going, install migrate-mongo.

npm install -g migrate-mongo

Then from the dbmigrations directory, run

migrate-mongo up

This will create the recipes collection and its validation schema. Now you can add recipes using the UI, or use the sample queries provided in docs/mongo-schema.md after the example schema definition.

adding the collection and schema validation

Using mongosh or some other tool, create the recipeBook database with the use recipeBook command. Then create the recipes collection with the schema validator.

See mongo-schema.md for the schema and a few example recipes insert commands.

database migrations

This project uses migrate-mongo to manage the mongo database and apply and rollback changes. Also see All you need to know about MongoDB schema migrations in node.js for a nice write-up for using migrate-mongo.

In the dbmigrations directory,

migrate-mongo create <create some_description_of_changes>

This will create a migration file in the dbmigrations/migrations directory, to which you can add the migration. Then to apply the migration

migrate-mongo up

And to revert to the prvious version

migrate-mongo down

raspberry π for recipes

For raspberry π 4b use the 64-bit debian images from raspberry pi

Use the set up docs as a base.

The Raspberry Pi Imager can be used to image the downloaded image onto the SD card. Just select the "Use Custom" option from the main menu when selecting the operating system.

setting up mongodb

binaries and instructions for 4.4.8

Now the above link also has binaries for mongo 5.0.5 (thanks Andy Felong!)

Once installed, you can start the mongo database with:

sudo systemctl start mongodb

To see the status of the service:

sudo systemctl status mongodb

To stop the service:

sudo systemctl stop mongodb

To enable the service to start automatically at boot:

sudo systemctl enable mongodb

pm2 (process manager)

npm install pm2@latest -g

To start with pm2, in the nextjs project directory, after running

npm run build

in the same directory, run

pm2 start npm --name "recipes" -- start -- -p 8080

Once started, you can get the status, stop, start, remove the process from any directory:

 $ pm2 delete 4
[PM2] Applying action deleteProcessId on app [4](ids: [ '4' ])
[PM2] [nextapp](4) ✓
┌─────┬────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name       │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 6   │ recipes    │ default     │ N/A     │ fork    │ 16125    │ 4m     │ 0    │ online    │ 0%       │ 53.9mb   │ pi       │ disabled │
└─────┴────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
pm2 stop <id>
pm2 start <id>
pm2 delete <id>

For more details about the process:

pm2 show recipes

To have pm2 maintain the list of processes and start-up when the server restarts see the pm2 persistent application docs.

setting up nginx

A good starting point is nginx beginners guide and nginx reverse proxy.

On debian (works on raspian) use apt and the default debian repository

sudo apt update
sudo apt install nginx

To verify that nginx has been installed properly, show it's version

sudo nginx -version

Then edit the /etc/nginx/nginx.conf file.

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    server {
        # all incoming request on port 80 (listen 80 is the default value and is omitted here)
        # get mapped to localhost:8080 on which the recipes are running
        location / {
            proxy_pass http://localhost:8080/;
        }
    }
}

Now start nginx

sudo nginx

Some useful commands: sudo nginx -s reload, sudo nginx -s stop.

This should already have set up nginx as a service. You can verify this with

systemctl status nginx

And you should be good to go.

About

next js app for the recipes

Resources

Stars

Watchers

Forks

Packages

No packages published