monorepofiy

This commit is contained in:
taskylizard
2024-02-25 01:31:53 +00:00
parent b693586301
commit 9065a0aeb7
42 changed files with 14 additions and 6 deletions

6
api/middleware/cors.ts Normal file
View File

@@ -0,0 +1,6 @@
import { corsEventHandler } from 'nitro-cors'
export default corsEventHandler((_event) => {}, {
origin: '*',
methods: '*'
})

View File

@@ -3,7 +3,6 @@ export default defineNitroConfig({
runtimeConfig: {
WEBHOOK_URL: process.env.WEBHOOK_URL
},
srcDir: '.vitepress',
routeRules: {
'/': {
cors: false

View File

@@ -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
View 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
View File

@@ -0,0 +1,3 @@
export default eventHandler(() => {
return { nitro: 'works' }
})

29
api/types/Feedback.ts Normal file
View 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>