Merge pull request #33 from calcom/fix/add-index

pull/9078/head
Agusti Fernandez 2022-04-08 23:21:58 +02:00 committed by GitHub
commit fbc83a5cc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 21 deletions

View File

@ -1,21 +0,0 @@
import { NextRequest, NextResponse } from "next/server";
// Not much useful yet as prisma.client can't be used in the middlewares (client is not available)
// For now we just throw early if no apiKey is passed,
// but we could also check if the apiKey is valid if we had prisma here.
export default async function requireApiKeyAsQueryParams({ nextUrl }: NextRequest) {
const response = NextResponse.next();
const apiKey = nextUrl.searchParams.get("apiKey");
if (apiKey) return response;
// if no apiKey is passed, we throw early a 401 unauthorized asking for a valid apiKey
else
new NextResponse(
JSON.stringify({
message:
"You need to pass an apiKey as query param: https://api.cal.com/resource?apiKey=<your-api-key>",
}),
{ status: 401, statusText: "Unauthorized" }
);
}

5
pages/api/index.ts Normal file
View File

@ -0,0 +1,5 @@
import type { NextApiRequest, NextApiResponse } from "next";
export default async function CalcomApi(req: NextApiRequest, res: NextApiResponse) {
res.status(201).json({ message: "Welcome to Cal.com API - docs are at https://docs.cal.com/api" });
}