or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-7/

URL Shortener Redirect Service

Build a simple URL shortener redirect service using Koa that handles URL-encoded redirect targets.

Requirements

The service should:

  • Accept requests to GET /r/:target where :target is a URL-encoded redirect destination
  • Decode the URL parameter and redirect the user to the decoded URL
  • Set the HTTP status code to 302 (temporary redirect)
  • Handle encoded URLs that contain special characters like slashes, colons, and query parameters
  • Return a 400 error if the target parameter is missing or invalid

Implementation

@generates

API

/**
 * Creates and returns a configured Koa application instance with redirect routing.
 *
 * @returns {Application} A Koa application instance
 */
function createApp() {
  // IMPLEMENTATION HERE
}

module.exports = { createApp };

Test Cases

Basic redirect handling

  • When a request is made to /r/https%3A%2F%2Fexample.com, the service redirects to https://example.com with status 302 @test
  • When a request is made to /r/https%3A%2F%2Fgithub.com%2Fkoajs%2Fkoa, the service redirects to https://github.com/koajs/koa with status 302 @test

Complex URL handling

  • When a request is made to /r/https%3A%2F%2Fexample.com%2Fsearch%3Fq%3Dhello%2520world, the service redirects to https://example.com/search?q=hello%20world with status 302 @test

Dependencies { .dependencies }

koa-route { .dependency }

Provides routing with URL parameter decoding support.

@satisfied-by

koa { .dependency }

Provides the web application framework.

@satisfied-by