In server/routes/media.routes.js, we will add the create route, and utilize the userByID method from the user controller. The userByID method processes the :userId parameter passed in the URL and retrieves the associated user from the database.
mern-mediastream/server/routes/media.routes.js:
router.route('/api/media/new/:userId') .post(authCtrl.requireSignin, mediaCtrl.create)router.param('userId', userCtrl.userByID)
A POST request to the create route will first make sure the user is signed in and then initiate the create method in the media controller.
Similar to the user and auth routes, we will have to mount the media routes on the Express app in express.js as follows.
mern-mediastream/server/express.js:
app.use('/', ...