fix cors
This commit is contained in:
parent
3a71e8f164
commit
7213a1f4af
6
.vitepress/middleware/cors.ts
Normal file
6
.vitepress/middleware/cors.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { corsEventHandler } from "nitro-cors";
|
||||||
|
|
||||||
|
export default corsEventHandler((_event) => { }, {
|
||||||
|
origin: "*",
|
||||||
|
methods: "*",
|
||||||
|
});
|
@ -47,5 +47,5 @@ export default defineEventHandler(async (event) => {
|
|||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
return "success";
|
return { status: "success" };
|
||||||
});
|
});
|
||||||
|
@ -42,12 +42,11 @@ async function handleSubmit(type?: string) {
|
|||||||
contactEmail: feedback.contactEmail,
|
contactEmail: feedback.contactEmail,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: fix this horror?
|
||||||
try {
|
try {
|
||||||
const response = await fetch("https://feedback.tasky.workers.dev", {
|
const response = await fetch("https://feedback.tasky.workers.dev", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Access-Control-Allow-Origin": "*",
|
|
||||||
"Access-Control-Allow-Methods": "POST",
|
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
@ -59,7 +58,9 @@ async function handleSubmit(type?: string) {
|
|||||||
error.value = data.error;
|
error.value = data.error;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
success.value = true;
|
if (data.status === "success") {
|
||||||
|
success.value = true;
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error.value = err;
|
error.value = err;
|
||||||
} finally {
|
} finally {
|
||||||
@ -103,7 +104,10 @@ async function handleSubmit(type?: string) {
|
|||||||
<textarea v-model="feedback.message" autofocus class="input" />
|
<textarea v-model="feedback.message" autofocus class="input" />
|
||||||
<p class="desc">Contacts, so we can get back to you. (Optional)</p>
|
<p class="desc">Contacts, so we can get back to you. (Optional)</p>
|
||||||
<textarea v-model="feedback.contactEmail" class="contact-input" />
|
<textarea v-model="feedback.contactEmail" class="contact-input" />
|
||||||
<button class="btn btn-primary" :disabled="!feedback.message" @click="handleSubmit()">
|
<button
|
||||||
|
class="btn btn-primary"
|
||||||
|
:disabled="feedback.message.length > 10"
|
||||||
|
@click="handleSubmit()">
|
||||||
Submit
|
Submit
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-glob": "^3.3.1",
|
"fast-glob": "^3.3.1",
|
||||||
"itty-fetcher": "^0.9.4",
|
"itty-fetcher": "^0.9.4",
|
||||||
|
"nitro-cors": "^0.7.0",
|
||||||
"nitropack": "latest",
|
"nitropack": "latest",
|
||||||
"pathe": "^1.1.1",
|
"pathe": "^1.1.1",
|
||||||
"unocss": "^0.57.1",
|
"unocss": "^0.57.1",
|
||||||
|
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@ -16,6 +16,9 @@ dependencies:
|
|||||||
itty-fetcher:
|
itty-fetcher:
|
||||||
specifier: ^0.9.4
|
specifier: ^0.9.4
|
||||||
version: 0.9.4
|
version: 0.9.4
|
||||||
|
nitro-cors:
|
||||||
|
specifier: ^0.7.0
|
||||||
|
version: 0.7.0
|
||||||
nitropack:
|
nitropack:
|
||||||
specifier: latest
|
specifier: latest
|
||||||
version: 2.7.2
|
version: 2.7.2
|
||||||
@ -4468,6 +4471,13 @@ packages:
|
|||||||
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
|
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
|
/nitro-cors@0.7.0:
|
||||||
|
resolution: {integrity: sha512-Mbb26M7TCKZxt8mOw5V9mVj4gCCv+/+LOy1QUUlk+HcMFn5CD4/irwg8IsoDg7NA+c441A0joC4n+mVFCNhu5g==}
|
||||||
|
dependencies:
|
||||||
|
h3: 1.8.2
|
||||||
|
ufo: 1.3.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
/nitropack@2.7.2:
|
/nitropack@2.7.2:
|
||||||
resolution: {integrity: sha512-6vQbGdBNR20N8wTChzIQUZQmNVhWVDrjUdpOYD68u2hlyUiJembth2fQuoWw3KlsoNYWFvcyqL9X3DPjjnoEUQ==}
|
resolution: {integrity: sha512-6vQbGdBNR20N8wTChzIQUZQmNVhWVDrjUdpOYD68u2hlyUiJembth2fQuoWw3KlsoNYWFvcyqL9X3DPjjnoEUQ==}
|
||||||
engines: {node: ^16.11.0 || >=17.0.0}
|
engines: {node: ^16.11.0 || >=17.0.0}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user