Create object to append to both HTTP and HTTPS Express Servers in Node.js -


ok, have node.js app 2 express servers. 1 listens on port 80 (http) , 1 on port 443 (https).

now, these not have same routes. quite contrary, things served on https on http. but, there overlap.

so, wondering there way 'bind' routes both secureapp , app call them such don't have write route twice?

ex. right have 2 sets of same route (one http , 1 https):

app.get('/tweet-stats.json', function(req, res){     res.set('content-type', 'application/json');     res.send(publictweetstatus()); });  secureapp.get('/tweet-stats.json', function(req, res){     res.set('content-type', 'application/json');     res.send(publictweetstatus()); }); 

i this:

model.get('/tweet-stats.json', function(req, res){     res.set('content-type', 'application/json');     res.send(publictweetstatus()); });  app.handle.bind(model); secureapp.handle.bind(model); 

is possible? make better coding manage 1 instance of particular route across ports.

why repeating yourself? block routes can't used

function secureonly(req, res, next) {   if (!req.secure) {     res.send(426, 'sorry')   else {     next()   } } 

and listen on 2 ports

http.createserver(app).listen(80) https.createserver(app).listen(443) 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -