Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // parse application/json
- app.use(bodyParser.json())
- var port = process.env.PORT || 8080; // set our port
- // ROUTES FOR OUR API
- // =============================================================================
- var router = express.Router(); // get an instance of the express Router
- var basicAuth = require('basic-auth');
- var auth = function (req, res, next) {
- function unauthorized(res) {
- res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
- return res.sendStatus(401);
- };
- var user = basicAuth(req);
- if (!user || !user.name || !user.pass) {
- return unauthorized(res);
- };
- //if (user.name === 'bwsfdc' && user.pass === 'e!!dQ0EJPCBft$evqtafQcjRaplhFu$yVqx5BD4KyF$YES0o!wlqoem5KL2RlqeG') {
- if (user.name === 'bwsfdc' && user.pass === 'S!!dQ0EXPCBft$evqtafQcjRaplhFu$yaqx5BD4KyF$DES0o!wlqoem5KL2Rlqe4') {
- return next();
- } else {
- return unauthorized(res);
- };
- };
- router.get('/', function(req, res) {
- res.sendStatus(500);
- });
- router.post('/send',auth, function(req, res) {
- });
- // REGISTER OUR ROUTES -------------------------------
- // all of our routes will be prefixed with /api
- app.use('/api', router);
- // START THE SERVER
- // =============================================================================
- app.listen(port);
- console.log('Running on port ' + port);
Add Comment
Please, Sign In to add comment