javascript - How to make route redirect or send JSON back depending on accept headers? -


i want send json if user accesses route , accept headers allow json, , want redirect user page if user accesses route , accept headers not allow json.

my solution hacky, involves inspecting req.headers.accept , seeing whether string contains json. if does, return json, else, redirect. there more optimal solution?

you can try res.format method.

res.format({   'application/json': function(){     res.send({ message: 'hey' });   },    default: function(){     res.redirect('nojson.html');   } }); 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -