Guest User

Untitled

a guest
Oct 16th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. // parse application/json
  2. app.use(bodyParser.json())
  3.  
  4.  
  5. var port = process.env.PORT || 8080; // set our port
  6.  
  7. // ROUTES FOR OUR API
  8. // =============================================================================
  9. var router = express.Router(); // get an instance of the express Router
  10.  
  11.  
  12. var basicAuth = require('basic-auth');
  13.  
  14. var auth = function (req, res, next) {
  15. function unauthorized(res) {
  16. res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
  17. return res.sendStatus(401);
  18. };
  19.  
  20. var user = basicAuth(req);
  21.  
  22. if (!user || !user.name || !user.pass) {
  23. return unauthorized(res);
  24. };
  25.  
  26. //if (user.name === 'bwsfdc' && user.pass === 'e!!dQ0EJPCBft$evqtafQcjRaplhFu$yVqx5BD4KyF$YES0o!wlqoem5KL2RlqeG') {
  27. if (user.name === 'bwsfdc' && user.pass === 'S!!dQ0EXPCBft$evqtafQcjRaplhFu$yaqx5BD4KyF$DES0o!wlqoem5KL2Rlqe4') {
  28. return next();
  29. } else {
  30. return unauthorized(res);
  31. };
  32. };
  33.  
  34. router.get('/', function(req, res) {
  35. res.sendStatus(500);
  36. });
  37.  
  38. router.post('/send',auth, function(req, res) {
  39.  
  40. });
  41.  
  42. // REGISTER OUR ROUTES -------------------------------
  43. // all of our routes will be prefixed with /api
  44. app.use('/api', router);
  45.  
  46. // START THE SERVER
  47. // =============================================================================
  48. app.listen(port);
  49. console.log('Running on port ' + port);
Add Comment
Please, Sign In to add comment