check token on api post request
This commit is contained in:
@@ -1,15 +1,20 @@
|
|||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import {store, html} from "@/store";
|
import { store, html } from "@/store";
|
||||||
|
import config from "@/config";
|
||||||
|
|
||||||
export default function handler(
|
export default function handler(
|
||||||
req: NextApiRequest,
|
req: NextApiRequest,
|
||||||
res: NextApiResponse<Record<string, string>>,
|
res: NextApiResponse<Record<string, string>>
|
||||||
) {
|
) {
|
||||||
if (req.method === 'POST') {
|
if (req.method === "POST") {
|
||||||
|
if (req.headers.token !== config.token) {
|
||||||
|
res.status(403).json({ error: "wrong token" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
// update store
|
// update store
|
||||||
console.log('admin', req.body)
|
console.log("admin", req.body);
|
||||||
const json = req.body
|
const json = req.body;
|
||||||
store.update(json)
|
store.update(json);
|
||||||
}
|
}
|
||||||
res.status(200).json(store.get());
|
res.status(200).json(store.get());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ import config from "@/config";
|
|||||||
|
|
||||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
if (req.method === "POST") {
|
if (req.method === "POST") {
|
||||||
|
if (req.headers.token !== config.token) {
|
||||||
|
res.status(403).json({ error: "wrong token" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
// update config
|
// update config
|
||||||
config.begin = req.body.begin ?? config.begin;
|
config.begin = req.body.begin ?? config.begin;
|
||||||
config.limit = req.body.limit ?? config.limit;
|
config.limit = req.body.limit ?? config.limit;
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import { html } from "@/store";
|
import { html } from "@/store";
|
||||||
|
import config from "@/config";
|
||||||
|
|
||||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
if (req.method === "POST") {
|
if (req.method === "POST") {
|
||||||
|
if (req.headers.token !== config.token) {
|
||||||
|
res.status(403).json({ error: "wrong token" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
html.set(req.body.html);
|
html.set(req.body.html);
|
||||||
}
|
}
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
|
|||||||
Reference in New Issue
Block a user