'use strict';

const service = require('feathers-mongoose');
const link = require('./link-model');
const hooks = require('./hooks');

module.exports = function() {
  const app = this;

  const options = {
    Model: link,
    paginate: {
      default: 5,
      max: 25
    }
  };

  // Initialize our service with any options it requires
  app.use('/links', service(options));

  // Get our initialize service to that we can bind hooks
  const linkService = app.service('/links');

  // Set up our before hooks
  linkService.before(hooks.before(linkService));

  // Set up our after hooks
  linkService.after(hooks.after);
};

@@ -156,15 +156,15 @@
 tion
+ 
 () %7B%0A
-  
+%09
 cons
@@ -178,18 +178,17 @@
  this;%0A%0A
-  
+%09
 const op
@@ -197,20 +197,18 @@
 ons = %7B%0A
-    
+%09%09
 Model: l
@@ -212,20 +212,18 @@
 : link,%0A
-    
+%09%09
 paginate
@@ -230,54 +230,350 @@
 : %7B%0A
-      default: 5,%0A      max: 25%0A    %7D%0A  %7D;%0A%0A  
+%09%09%09default: 5,%0A%09%09%09max: 25%0A%09%09%7D%0A%09%7D;%0A%0A%09let linkService = service(options);%0A%0A%09function redirectToTarget(req, res, next) %7B%0A%09%09if(req.method == 'GET') %7B%0A%09%09%09const linkId = req.params.__feathersId;%0A%09%09%09linkService.get(linkId)%0A%09%09%09%09.then(data =%3E res.redirect(data.target))%0A%09%09%09%09.catch(error =%3E res.status(500).send(error));%0A%09%09%7D else %7B%0A%09%09%09next();%0A%09%09%7D%0A%09%7D%0A%0A%09
 // I
@@ -623,18 +623,17 @@
 equires%0A
-  
+%09
 app.use(
@@ -642,34 +642,45 @@
 link
-s
 ', 
-service(options)
+redirectToTarget, linkService
 );%0A%0A
-  
+%09
 // G
@@ -735,16 +735,9 @@
 oks%0A
-  const 
+%09
 link
@@ -768,16 +768,14 @@
 link
-s
 ');%0A%0A
-  
+%09
 // S
@@ -793,26 +793,25 @@
 efore hooks%0A
-  
+%09
 linkService.
@@ -846,18 +846,17 @@
 ice));%0A%0A
-  
+%09
 // Set u
@@ -877,10 +877,9 @@
 oks%0A
-  
+%09
 link

Implement redirection express middleware