Making a To-Do List With flatiron.js (Story 1)
This post continues the creation of a to-do list with flatiron.js.
Previous Stories in this Series
We’ll use connect‘s
session
middleware to get this going. In the documentation, it shows that we must
include the cookieParser
middleware first and then pass a token into the
session
middleware to compute the hash stored in the session cookie. In
our server file, let’s implement that.
1 | // server.js |
That should be all there is to it. Run npm start
from the command line
and navigate to http://localhost:8090.
Problem: Object [object Object] has no method ‘_implicitHeader’
Well, that didn’t work. The server threw an exception and our process exited. The top two entries in the stack trace show us some relevant information.
1 | "TypeError: Object [object Object] has no method '_implicitHeader'", |
There’s a problem in the session middleware. If we head over to its github
repo and look at the
history of session.js,
then we find out that the version of session.js
that we installed with
version 1.8.5 of connect is at least six months old. Well, let’s update
connect to the 2.0.0alpha version by specifying the URL to the tarball. Change
package.json
to read
1 | { |
Run the following commands at the command line.
1 | npm uninstall connect |
Once again, navigate to http://localhost:8090 and let’s see what we get.
Another problem: connect.cookieParser("secret") required for security when using sessions
Well, looks like the API changed between connect@1.8.5 and
connect@2.0.0. Let’s change the server.js
file to honor the error
message. Since the cookieParser now takes the secret, I bet that we don’t
need to provide it to the session. Change server.js
to read
1 | // server.js |
Run the following commands at the command line.
1 | npm start |
Once again, navigate to http://localhost:8090 and let’s see what we get.
Problem revisited: Object [object Object] has no method ‘_implicitHeader’
Seriously? Don’t they release new versions of connect? Ever?
Fine, we’ll install HEAD instead of 2.0.0.alpha. Change package.json
to
read
1 | { |
Run the following commands at the command line.
1 | npm uninstall connect |
Once again, navigate to http://localhost:8090 and let’s see what we get.
Problems resolved
Finally, an empty page in the browser and no uncaught exceptions in our server.
“What did you learn today, Ian?”
“I learned that flatiron may be backwards compatible with connect, but connect doesn’t have a new release to make it compatible with node@0.6.”