Skip to content

Commit

Permalink
feat: deep link API
Browse files Browse the repository at this point in the history
# Why

To integrate with the OTel GPT, it would be necessary that OTelBin
exposes an API to create deep links.

# What

Add an API under `POST /deep-link` that takes a collector config
within the request body and that outputs a deep link within the
`Location` response header and within the body (`text/plain` body).
  • Loading branch information
bripkens committed Jan 18, 2024
1 parent b76fe8f commit a8c583d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/otelbin/src/app/deep-link/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: 2024 Dash0 Inc.
// SPDX-License-Identifier: Apache-2.0

import { type NextRequest, NextResponse } from "next/server";
import { serializeUrlState } from "~/lib/urlState/serializeUrlState";
import { editorBinding } from "~/components/monaco-editor/editorBinding";
import { URLSearchParams } from "next/dist/compiled/@edge-runtime/primitives";

export async function POST(request: NextRequest): Promise<NextResponse> {
const body = await request.text();
const emptyParams = new URLSearchParams();
const pathName = serializeUrlState([editorBinding], "/", emptyParams, emptyParams, {
[editorBinding.name]: body,
});
const url = new URL(pathName, request.nextUrl).toString();
return NextResponse.json(
{
deepLink: url,
},
{
status: 200,
headers: {
Location: url,
},
}
);
}

0 comments on commit a8c583d

Please sign in to comment.