dispatch:short-url

v1.0.0Published 10 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

dispatch:short-url

Create short urls, supports android and ios intents / custom-url shemes.

Usage examples

1  // Setup a url shortner
2  shortUrl = new UrlShortner({
3    prefix: '/s'     // If the shortner is to co-exist with
4                     // the application then prefix, default is /s/XXXXXXXX
5    // rateLimit: {  // Set rate limit options on the http point
6    //   totalRequests: 10,
7    //   every: 60000
8    // },
9    // collectionName: '', // Overwrite the default collection for short urls
10    fallbackUrl: 'https://go.to.here.if.the.redirect.fails',
11    // debug: true // Make it verbose,
12    // payload: { foo: bar } // Abillity to add payload for events
13    startServer: true // Start the http(s) restpoint, default is false
14  });
15
16  // Create a short url
17  shortUrl = createShortUrl('https://if.this.is.a.long.url.then.shorten.me');
18
19  // Create a short url for android and iOS
20  // Note: Provide the android fallback url in the intent for the best
21  // user experience
22  shortUrl = createShortUrl('https://if.this.is.a.long.url.then.shorten.me', {
23    androidUrl: 'intent://?platform=android#Intent;scheme=dispatchdeeplinktest;'+
24              'package=me.dispatch.qa.test.deep.link;' +
25              'S.browser_fallback_url=http://www.google.com;end',
26      iosUrl: 'dispatchdeeplinktest://?shorturl=ios'
27  });
28
29  // Limit usage
30  shortUrl = createShortUrl('https://if.this.is.a.long.url.then.shorten.me', {
31    oneTimeLink=true // Set true and this link will only work once
32  });
33
34  // or... have it expire
35  shortUrl = createShortUrl('https://if.this.is.a.long.url.then.shorten.me', {
36    expireAt=new Date(new Date().getTime() + 10000) // Set expiration time/date
37  });
1  // Add the "dispatch:deep-link" package
2  // Initialize the deepLink - customURL scheme
3  deepLink = new DeepLink('dispatchdeeplinktest', {
4    fallbackUrl: 'https:/go.to.here.if.the.redirect.fails', // Adding a fallback here will add it to the android intent
5    appId: 'me.dispatch.qa.test.deep.link'
6  });
7
8  // Setup a url shortner
9  shortUrl = new UrlShortner({
10    prefix: '/s',
11    fallbackUrl: 'https://go.to.here.if.the.redirect.fails',
12  });
13
14  // Create some data to send
15  var payload = {
16    foo: 'bar',
17    createdAt: new Date() // Supports EJSON
18    bar: {                // and
19      foo: 'bar2'         // Nested data
20    }
21  };
22
23  // Create the shortUrl
24  shortUrl = createShortUrl('https://if.this.is.a.long.url.then.shorten.me', {
25    androidUrl: deepLink.androidLink('', payload),
26      iosUrl: deepLink.iosLink('', payload)
27  });

Events emitted

The urlShortner will emit the following event:

  • this.emit('redirect', event); (redirect or by html template)
  • this.emit('expired', event); (By date or usage)
  • this.emit('error', event);