import 'package:dart_frog/dart_frog.dart';
import 'package:new_backend/shrink_ray.dart';

Future<Response> onRequest(RequestContext context, String urlPath) async {
  switch (context.request.method) {
    case HttpMethod.put:
    case HttpMethod.delete:
    case HttpMethod.head:
    case HttpMethod.options:
    case HttpMethod.patch:
    case HttpMethod.post:
      return Response(statusCode: 404);
    case HttpMethod.get:
      final maybeUrl = shrunkUrls[urlPath];
      switch (maybeUrl) {
        case null:
          return Response(statusCode: 404);
        default:
          return Response(statusCode: 308, headers: {'Location': maybeUrl});
      }
  }
}
