Add d to res.locals so can be accessed elsewhere

pick feature from HabitRPG fork

https://github.com/HabitRPG/domain-middleware