mirror of
https://github.com/MedzikUser/gatsby-pingbot
synced 2024-08-15 03:20:27 +00:00
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { VercelRequest, VercelResponse } from '@vercel/node'
|
|
|
|
import addURL from '../lib/api/add'
|
|
import deleteURL from '../lib/api/delete'
|
|
|
|
import dbConnect from '../lib/dbConnect'
|
|
import URLModel from '../lib/schema'
|
|
|
|
export default async (request: VercelRequest, response: VercelResponse) => {
|
|
const { method } = request
|
|
|
|
switch (method) {
|
|
case 'POST':
|
|
if (!request.body || !request.body.url) {
|
|
return response.status(400).json({
|
|
success: false,
|
|
message: 'Invalid body'
|
|
})
|
|
}
|
|
|
|
return addURL(request.body.url, response)
|
|
case 'DELETE':
|
|
if (!request.query.url) {
|
|
return response.status(400).json({
|
|
success: false,
|
|
message: 'Invalid body'
|
|
})
|
|
}
|
|
|
|
if (typeof request.query.url != 'string') {
|
|
return response.status(400).json({
|
|
success: false,
|
|
message: 'Query URL isn\'t string'
|
|
})
|
|
}
|
|
|
|
return deleteURL(request.query.url, response)
|
|
default:
|
|
await dbConnect()
|
|
|
|
response.status(200).json({
|
|
db: await URLModel.find()
|
|
})
|
|
|
|
break
|
|
}
|
|
}
|