monorepofiy
This commit is contained in:
6
api/middleware/cors.ts
Normal file
6
api/middleware/cors.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { corsEventHandler } from 'nitro-cors'
|
||||
|
||||
export default corsEventHandler((_event) => {}, {
|
||||
origin: '*',
|
||||
methods: '*'
|
||||
})
|
@@ -3,7 +3,6 @@ export default defineNitroConfig({
|
||||
runtimeConfig: {
|
||||
WEBHOOK_URL: process.env.WEBHOOK_URL
|
||||
},
|
||||
srcDir: '.vitepress',
|
||||
routeRules: {
|
||||
'/': {
|
||||
cors: false
|
||||
|
@@ -8,7 +8,7 @@
|
||||
"dev": "nitropack dev",
|
||||
"build": "nitropack build",
|
||||
"preview": "node .output/server/index.mjs",
|
||||
"postinstall": "nitropack prepare"
|
||||
"types": "nitropack prepare"
|
||||
},
|
||||
"dependencies": {
|
||||
"itty-fetcher": "^0.9.4",
|
||||
|
32
api/routes/index.post.ts
Normal file
32
api/routes/index.post.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { fetcher } from 'itty-fetcher'
|
||||
import { FeedbackSchema, getFeedbackOption } from '../types/Feedback'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { message, page, type } = await readValidatedBody(
|
||||
event,
|
||||
FeedbackSchema.parseAsync
|
||||
)
|
||||
const env = useRuntimeConfig(event)
|
||||
|
||||
let description = `${message}\n\n`
|
||||
if (page) description += `**Page:** \`${page}\``
|
||||
|
||||
await fetcher()
|
||||
.post(env.WEBHOOK_URL, {
|
||||
username: 'Feedback',
|
||||
avatar_url:
|
||||
'https://i.kym-cdn.com/entries/icons/facebook/000/043/403/cover3.jpg',
|
||||
embeds: [
|
||||
{
|
||||
color: 3447003,
|
||||
title: getFeedbackOption(type).label,
|
||||
description
|
||||
}
|
||||
]
|
||||
})
|
||||
.catch((error) => {
|
||||
throw new Error(error)
|
||||
})
|
||||
|
||||
return { status: 'ok' }
|
||||
})
|
3
api/routes/test.ts
Normal file
3
api/routes/test.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default eventHandler(() => {
|
||||
return { nitro: 'works' }
|
||||
})
|
29
api/types/Feedback.ts
Normal file
29
api/types/Feedback.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import z from 'zod'
|
||||
|
||||
export const FeedbackSchema = z.object({
|
||||
message: z.string().min(5).max(1000),
|
||||
type: z.enum(['bug', 'suggestion', 'appreciate', 'other']),
|
||||
page: z.string().optional()
|
||||
})
|
||||
|
||||
export const feedbackOptions = [
|
||||
{ label: '🐞 Bug', value: 'bug' },
|
||||
{
|
||||
label: '💡 Suggestion',
|
||||
value: 'suggestion'
|
||||
},
|
||||
{ label: '📂 Other', value: 'other' },
|
||||
{
|
||||
label: '❤️ Appreciation',
|
||||
value: 'appreciate'
|
||||
}
|
||||
]
|
||||
|
||||
export function getFeedbackOption(value: string): {
|
||||
label: string
|
||||
value: string
|
||||
} {
|
||||
return feedbackOptions.find((option) => option.value === value)
|
||||
}
|
||||
|
||||
export type FeedbackType = z.infer<typeof FeedbackSchema>
|
Reference in New Issue
Block a user