-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a middleware, refactors outline.ts
- Loading branch information
1 parent
0761993
commit f850c30
Showing
9 changed files
with
67 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { NextRequest } from "next/server"; | ||
|
||
// Limit the middleware to paths starting with `/api/` | ||
export const config = { | ||
matcher: "/api/:function*", | ||
}; | ||
|
||
export function middleware(req: NextRequest) { | ||
const key: string = req.headers.get("x-api-key") as string; | ||
const API_SECRET_KEY = process.env.API_SECRET_KEY; | ||
if (!(key && key === API_SECRET_KEY)) { | ||
return Response.json( | ||
{ success: false, message: "INVALID_API_KEY" }, | ||
{ status: 403 }, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { NextApiResponse, NextApiRequest } from "next"; | ||
import { processUserStats, getStats } from "@/vpnmanager/lib/statistics"; | ||
import { RestMethodFunctions, RestMethods } from "@/vpnmanager/types"; | ||
|
||
const methodToFunction: RestMethodFunctions = { | ||
POST: processUserStats, | ||
GET: getStats, | ||
}; | ||
|
||
export async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
try { | ||
const statFunc = methodToFunction[req.method as RestMethods]; | ||
if (!statFunc) { | ||
return res.status(404).json({ message: "Requested path not found" }); | ||
} | ||
const data = await statFunc(req); | ||
return res.status(200).json(data); | ||
} catch (error) { | ||
return res.status(500).json(error); | ||
} | ||
} | ||
export default handler; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters