-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
58 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useState, type FormEvent } from "react"; | ||
|
||
const LinkForm = () => { | ||
const [message, setMessage] = useState(""); | ||
|
||
async function submit(e: FormEvent<HTMLFormElement>) { | ||
e.preventDefault(); | ||
|
||
const formData = new FormData(e.target as HTMLFormElement); | ||
const response = await fetch("/api/create", { | ||
method: "POST", | ||
body: formData, | ||
}); | ||
const data = await response.json(); | ||
|
||
if (data.message) { | ||
setMessage(data.message); | ||
} | ||
} | ||
|
||
return ( | ||
<form | ||
className="flex flex-col" | ||
onSubmit={submit} | ||
> | ||
<label> | ||
Original | ||
<input | ||
type="url" | ||
name="original" | ||
className="bg-purple-100" | ||
/> | ||
</label> | ||
<button>Send</button> | ||
{message.length > 0 ? <p>{message}</p> : null} | ||
</form> | ||
); | ||
}; | ||
|
||
export { LinkForm }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { APIRoute } from "astro"; | ||
|
||
export const POST: APIRoute = async ({ request }) => { | ||
const formData = await request.formData(); | ||
const original = formData.get("original"); | ||
|
||
if (!original) { | ||
return new Response(JSON.stringify({ message: "Missing original URL" }), { status: 400 }); | ||
} | ||
|
||
return new Response(JSON.stringify({ message: "success!" }), { status: 200 }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46e7265
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
link-shortener – ./
link-shortener-git-main-charles-wangs-projects.vercel.app
link-shortener-charles-wangs-projects.vercel.app
go.czw.sh