write.io week 6 — Sessions & Servers

This week we mostly did infrastructure work.

Session Management

First attempts at session management. We tried using express-session and express-socket.io-session to finally handle socket.io “unorderly” disconnecetions. After putting several hours into this without success, we left the failing test ignored/xit and opened an issue, to be revisited in the future.

Unifying API & Webpack servers

Ever since switching to the Webpack template a couple of weeks ago there was an issue that nagged me: Our codebase “forced” us to start two separate servers on two different ports (One for Webpack, and another for our JSON API & socket.io). We made it work back then by proxying everything except socket.io, and manually changing the socket.io port.

This solution couldn’t work in this form with sessions due to Same-origin policy, so the quick-and-easy solution we found was to unify the two servers into one. The combined server works, with some technical debt, mostly in the form of unclean/long code and Webpack’s production server (we’re only dealing with the dev server so far).

Test improvements

We’re learning the fine points of working with mocha/Nightmare tests. Today I learned that after every test I need to add a catch clause, otherwise if it fails, it waits for the test timeout instead of immediately failing:

it(‘should show login form when loaded’, function (done) {
newNightmare()
.goto(url)
.evaluate(function () {
return document.querySelectorAll(‘div.home’).length;
})
.run(function (err, result) {
result.should.equal(1);
done();
})
.catch(done); // <---- Out latest addition
});

I’m sure there’s a cleaner way to do this, will do some refactoring there in the future.

Game page

Finally, we did some work on the game page, including some templating & css work. It’s too early to show it here, maybe we’ll be able to show an early, ugly preview next week.


That’s it for now, stay tuned, and send us your pull requests.