← All projects

CarlPapa

A recipe app from July 2015, built with Carl Brown: an AngularJS client generated with Yeoman, styled with Materialize, on an Express and MongoDB API that was partway into adding JWT login.

CarlPapa's edit view: a light gray navigation bar with carlpapa and Home, the heading Modify Buttermilk Pancakes Recipe, underlined fields for the recipe name, four ingredients (2 cups flour, 2 cups buttermilk, 2 eggs, 3 tablespoons melted butter) and an empty fifth one, the instructions, and teal Save Recipe and Delete Recipe buttons.
Editing a recipe. Running locally from the repository's July 24, 2015 commit, the last one where the client and the API still matched, with recipes typed in for the capture.

CarlPapa is a recipe app built in July 2015 with Carl Brown (carlbrown64 on GitHub). Its README promises “the best damn cooking app you would ever want!!!!” It keeps a list of recipes, each with a name, its ingredients and instructions, and lets you add, edit and delete them.

The repository started on July 2 with an Express server and an AngularJS client generated by Yeoman. Carl wrote most of the app from there: the recipe views and controllers, the recipe API, and a JWT login that was still in progress when the commits stopped on July 31, 2015.

What it does

At its July 24 commit, the client and the API work end to end:

  • The home view lists every recipe by name, with an Add Recipe button.
  • The add form has a name, ingredients and instructions. When you leave the last ingredient field with something in it, a new empty one appears. A recipe needs a name, instructions and at least one ingredient before it’s sent.
  • Clicking a recipe opens it for editing. Save Recipe turns the button into “Recipe Saved!” for five seconds, and Delete Recipe removes the recipe and goes back to the list.

How it’s built

The client started from generator-angular 0.11.1, with a Gruntfile for serving, building and testing (Compass for Sass, Karma with PhantomJS) and Bower for the front-end libraries. ui-router was in place from the first commit, with states for the list, add and edit views. Materialize 0.97 gives it the underlined fields and teal buttons, on top of Bootstrap’s Sass from the generator. The controllers talk to the API with $http.

The server is Express 4.0 with Mongoose 3.6. At the July 24 commit it’s a REST API at /api/recipe that lists and creates recipes, and reads, updates and deletes one by id.

Where it stopped

The last week added login. The server gained /api/createAccount and /api/authenticate, which signs a token with jsonwebtoken, and a middleware that guards every route after them. The client gained a login view that signs in through Satellizer.

Lines 112 to 140 of server.js: an Express router middleware that reads a token from the request body, the query string or an x-access-token header, verifies it with jwt.verify against the app's secret, stores the decoded token on the request, and otherwise answers 403 with No token provided.
The token check in the server's last commit. Every route after it needs a token.

At the last commit, signing in works and Satellizer stores the token. But the recipe routes had become empty stubs in the rewrite, the client now asks for recipes at /api/ instead of /api/recipe/, and Satellizer sends the token in an Authorization header that the middleware doesn’t read, so the recipe list comes back 403 with “No token provided.” The commit that started the rewrite says so: “updated express router. Auth is broken”. In this version, passwords are also stored and compared as plain text.

The same token check turns up a month later in material.chef, the next recipe app here, this time with a React and Flux client and bcrypt-hashed passwords.

Running it today

  • Server. With Node 6, run npm install in server, add a config.js (git ignores it) with a MongoDB db URL and a secret, and run node server.js. It listens on port 9090, which the client expects. MongoDB 3.6 still works with Mongoose 3.6.
  • Libraries. Install the Bower packages at the versions their ranges resolved to in July 2015: AngularJS 1.4.3, ui-router 0.2.15, Materialize 0.97.0, bootstrap-sass 3.3.5, Satellizer 0.11.3 and jQuery 2.1.4. AngularJS 1.4 matters: the controllers use $http’s .success(), which AngularJS 1.6 removed, and ^1.3.0 now resolves to 1.8.
  • Client. grunt serve needs Ruby for Compass. Compiling app/styles/main.scss with Dart Sass, with bower_components as a load path, into .tmp/styles works, and then any static server can serve .tmp, bower_components and app the way the Gruntfile’s connect task does.

To see the working app, check out commit f91adbc. The last commit shows the login screen and an empty list.

The creation date shown here is the GitHub repository’s UTC creation date. The screenshots were captured by running the July 24, 2015 commit locally from its source with Node 6, MongoDB 3.6 and recipes typed in for the captures, and the code card shows the server’s source at the last commit.

Keyboard shortcuts

Shortcuts stay out of text fields. Extra shortcuts are off until you enable them on this device. Ctrl or Command K is always available.

?
Open this help
Ctrl / ⌘ K
Open site search
Alt A
Browse articles
Alt R
Open your reading list
Alt T
Browse topics
Escape
Close dialogs or leave article focus mode