// resolveLink — resolve a short code to its destination URL (the read side of // a link shortener; `shareLink` is the write side). // // Demonstrates: GET with a query param, a lookup, and a 404 via // `ServerlessHttpError` when the code is unknown. Swap the in-memory map for a // KV / D1 / database read in a real shortener — the shape stays the same. // // curl 'http://localhost:8910/?code=docs' import { Effect, Schema } from 'effect' import { defineServerless, ServerlessHttpError } from '@voltro/serverless' const LINKS: Record = { docs: 'https://voltro.dev/docs', gh: 'https://github.com/SinPP', home: 'https://voltro.dev', } export default defineServerless({ name: 'resolve-link', method: 'GET', input: Schema.Struct({ code: Schema.String.pipe(Schema.minLength(1)) }), output: Schema.Struct({ code: Schema.String, url: Schema.String }), handler: ({ code }, _ctx) => Effect.gen(function* () { const url = LINKS[code.toLowerCase()] if (!url) { return yield* Effect.fail(new ServerlessHttpError({ status: 404, message: 'unknown-code', detail: code })) } return { code, url } }), })