set cookies correctly when running on localhost

if you set domain= localhost when setting a cookie, it's just silently dropped.  So adding some code to not specify the domain if it's locahost.