How to use express-promise-router - 10 common examples

To help you get started, we’ve selected a few express-promise-router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github freeCodeCamp / pantry-for-good / server / routes / donor.js View on Github external
export default () => {
  const {requiresLogin} = userController
  const {hasAuthorization} = donorController

  const donorRouter = Router({mergeParams: true})

  // Donor routes for users
  donorRouter.route('/donor')
    .post(requiresLogin, donorController.create)
  donorRouter.route('/donor/:donorId')
    .get(requiresLogin, hasAuthorization, donorController.read)
    .put(requiresLogin, hasAuthorization, donorController.update)

  // Donor routes for admin
  donorRouter.route('/admin/donors')
    .get(donorController.list)
  donorRouter.route('/admin/donors/:donorId')
    .get(donorController.read)
    .put(donorController.update)
    .delete(donorController.delete)
github freeCodeCamp / pantry-for-good / server / routes / volunteer.js View on Github external
export default () => {
  const {requiresLogin} = userController
  const {hasAuthorization} = volunteerController

  const volunteerRouter = Router({mergeParams: true})

  // Volunteer routes for user
  volunteerRouter.route('/volunteer')
    .post(requiresLogin, volunteerController.create)
  volunteerRouter.route('/volunteer/:volunteerId')
    .get(requiresLogin, hasAuthorization, volunteerController.read)
    .put(requiresLogin, hasAuthorization, volunteerController.update)

  // Volunteer routes for admin
  volunteerRouter.route('/admin/volunteers')
    .get(volunteerController.list)
  volunteerRouter.route('/admin/volunteers/:volunteerId')
    .get(volunteerController.read)
    .put(volunteerController.update)
    .delete(volunteerController.delete)
github Jacwutang / CryptoEngineX / routes / index.js View on Github external
const router = require("express-promise-router").Router();

const db = require("../db");

// GET home page
router.get("/", (req, res) => {
  res.send("Home");
});

module.exports = router;
github CodeForSocialGood / calltocode.org / server / routes / api / users.js View on Github external
import expressPromiseRouter from 'express-promise-router'

import auth from '../../lib/middleware/auth'
import _users from '../controllers/users'

const router = expressPromiseRouter()
const users = _users._init()

router.route('/current')
  .get(auth.required, users.getCurrent)
  .put(auth.required, users.putCurrent)

router.route('/')
  .get(auth.optional, users.getUsers)
  .post(auth.optional, users.createUser)

router.route('/login')
  .post(users.login)

router.route('/salt')
  .get(users.getSalt)
github bwbwbwbw / DummyCTFPlatform / src / webControllers / dashboard.js View on Github external
export default (DI, parentRouter, app) => {

  const systemPropertyService = DI.get('systemPropertyService');
  const contestService = DI.get('contestService');

  const router = Router();
  parentRouter.use('/', router);

  router.get('/',
    async (req, res) => {
      let contest = null;
      const contestId = await systemPropertyService.get('current_contest', null);
      if (contestId !== null) {
        contest = await contestService.getContestObjectById(contestId, false);
      }
      res.render('dashboard', { currentContest: contest });
    }
  );

};
github bwbwbwbw / DummyCTFPlatform / src / webControllers / api / challenge.js View on Github external
export default (DI, parentRouter, app) => {

  const challengeService = DI.get('challengeService');

  const router = Router();
  parentRouter.use('/challenges', router);

  router.get('/',
    async (req, res) => {
      const challenges = await challengeService.getChallenges();
      res.json(challenges);
    }
  );

  router.post('/',
    challengeService.checkBodyForCreateOrEdit,
    libRequestChecker.raiseValidationErrors,
    async (req, res) => {
      const challenge = await challengeService.createChallenge(req.body);
      res.json(challenge);
    }
github freeCodeCamp / pantry-for-good / server / routes / media.js View on Github external
export default () => {
  const mediaRouter = Router({mergeParams: true})

  mediaRouter.route('/admin/media/upload')
    .post(upload.fields([
      {name: 'logo', maxCount: 1},
      {name: 'signature', maxCount: 1},
      {name: 'favicon', maxCount: 1}
    ]), mediaController.upload)

  mediaRouter.route('/media')
    .get(mediaController.read)

  return mediaRouter
}
github bwbwbwbw / DummyCTFPlatform / src / webControllers / user.js View on Github external
export default (DI, parentRouter, app) => {

  const router = Router();
  parentRouter.use('/user', router);

  router.get('/signin',
    (req, res) => {
      res.render('user/signin');
    }
  );

  router.get('/register',
    (req, res) => {
      res.render('user/register');
    }
  );

};
github bwbwbwbw / DummyCTFPlatform / src / webControllers / public / announcement.js View on Github external
export default (DI, parentRouter, app) => {

  const announcementService = DI.get('announcementService');

  const router = Router();
  parentRouter.use(
    '/announcements',
    router
  );

  router.get('/',
    async (req, res) => {
      const announcements = await announcementService.getAnnouncements();
      res.json(announcements);
    }
  );

};

express-promise-router

A lightweight wrapper for Express 4's Router that allows middleware to return promises

MIT
Latest version published 3 years ago

Package Health Score

64 / 100
Full package analysis

Popular express-promise-router functions