Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@dizzzmas/sst-url-shortener
Advanced tools
[![NPM version](https://img.shields.io/npm/v/@dizzzmas/sst-url-shortener.svg)](https://npmjs.org/package/@dizzzmas/sst-url-shortener) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@dizzzmas/sst-url-shortener)
Host your own URL shortener on AWS with SST and chop up those beefy links in a breeze!
If this is your first time using SST or deploying to AWS, make sure you have the AWS credentials properly setup
This is for cases when you can't or don't want to integrate the URLShortener
component into your existing SST app.
Here we will create a new SST app and use an OpenAPI SDK to integrate with our backend deployed elsewhere.
mkdir my-shortener-app && cd my-shortener-app
npm init -y
URLShortener
component:npx sst@latest init
npm install @dizzzmas/sst-url-shortener
sst.config.ts
:/// <reference path="./.sst/platform/config.d.ts" />
import { UrlShortener } from "@dizzzmas/sst-url-shortener";
export default $config({
app(input) {
return {
name: "url-shortener",
removal: input?.stage === "production" ? "retain" : "remove",
home: "aws",
};
},
async run() {
const urlShortener = new UrlShortener({})
return {
api: urlShortener.api.url,
}
},
});
npx sst dev
Notice that our app once deployed returns a URL of an API endpoint.
By default the API doesn't require authentication and has Swagger UI enabled.
We can visit {api}/ui
to access the swagger UI and test our API.
SDKs are available for:
Below is an example of using the JS SDK to shorten a URL:
Install the SDK in your backend project
npm install @dizzzmas/sst-url-shortener-sdk
Use it:
import SstURLShortener from '@dizzzmas/sst-url-shortener-sdk';
const client = new SstURLShortener({
baseURL: "YOUR_API_URL",
bearerToken: undefined // auth disabled in this example
});
async function main() {
const newUrl = await client.urls.create({
originalUrl: "https://sst.dev/docs"
});
const shortUrl = newUrl.result.shortUrl;
console.log(shortUrl); // the shortened URL
const urls = await client.urls.search({});
console.log(urls.result);
}
main();
Install the component:
npm install @dizzzmas/sst-url-shortener
Modify sst.config.ts
to include the component:
import { UrlShortener } from "@dizzzmas/sst-url-shortener";
async run() {
// ...your existing components
const urlShortener = new UrlShortener({});
// link URL shortener to another component e.g. a lambda function
const example = new sst.aws.Function("Example", {
link: [...urlShortener.link],
handler: "example.handler",
url: true,
})
}
Inside the example.ts
Lambda handler:
import { ShortUrl } from "@dizzzmas/sst-url-shortener"
export const handler = async () => {
const { shortUrl } = await ShortUrl.create({
originalUrl: "https://sst.dev/docs"
})
console.log("new short url", shortUrl)
const searchResult = await ShortUrl.search({})
console.log("search results", searchResult)
return shortUrl
}
API bearer authentication is disabled by default and can be enabled via setting enableApiAuth
to true
on the component.
const shortener = new UrlShortener({
enableApiAuth: true,
})
Make sure you specify the Bearer token expected by the API for authentication.
The Bearer token can be set via UrlShortenerApiAuthKey
SST Secret and defaults to your_secret
# set the secret
npx sst secret set UrlShortenerApiAuthKey "YOUR_TOKEN"
Swagger UI is enabled by default and can be disabled via settings enableOpenApiDocs
to false
on the component.
const shortener = new UrlShortener({
enableOpenApiDocs: false,
})
You can specify a custom domain for the URL shortener and its API.
const shortener = new UrlShortener({
domain: {
name: "share.acme.com",
dns: sst.aws.dns()
}
})
The above example will results in short URLs looking like https://share.acme.com/etogiyeu
, and the API looking like https://api.share.acme.com/ui
Custom domains work out of the box if you use AWS Route53, Cloudflare or Vercel as your DNS provider, but will require manual setup for other providers. Please check out SST Custom Domains docs for more info.
Short id is the alphanumeric identifier for your URLs generated using cuid2
e.g. in https://share.acme.com/etogiyeu
the short id is etogiyeu
Its length can be anywhere from 4 to 24 characters and defaults to 8.
const shortener = new UrlShortener({
shortIdLength: 12
})
You can fully customize the underlying resources thanks to the SST Transform feature.
const shortener = new UrlShortener({
transform: {
redirectHandler: {
function: {
timeout: 30
}
}
}
})
FAQs
[![NPM version](https://img.shields.io/npm/v/@dizzzmas/sst-url-shortener.svg)](https://npmjs.org/package/@dizzzmas/sst-url-shortener) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@dizzzmas/sst-url-shortener)
The npm package @dizzzmas/sst-url-shortener receives a total of 20 weekly downloads. As such, @dizzzmas/sst-url-shortener popularity was classified as not popular.
We found that @dizzzmas/sst-url-shortener demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.