IP Address Tracker built with HTML | CSS | REACT - MikDra1
Design comparison
Solution retrospective
π» Hello, Frontend Mentor Community,
This is my solution for the IP Address Tracker.
- Scored 95,5% on Google Pagespeed Insights! π
- Solution with 100% W3C validation accuracy π
- Custom-built CSS animations for a smooth user experience π«
- You can check both: IP Adress and Domain π₯
- Custom validation π«
- Custom loading state when fetching data from an API π΄
π οΈ Built with:
- HTML β¨
- CSS π¨
- JavaScript π§Ύ
- React βοΈ
- Vite.js π‘
-
Fully responsive design crafted with a mobile-first approach π²
-
Enjoyed every moment coding this! π
-
Feedback is always welcomeβletβs grow together! π±
-
Completed 10 out of 13 Intermediate Challenges so farβkeeping up the momentum! π₯
-
π¨βπ» Join me on my coding journey as I tackle advanced challenges and add innovative touches to every project.
-
As I am starting my journey with React I'm really looking forward to hearing your thoughts and suggestions! π‘
-
I would be grateful if someone could tell me how to add a keyevent on "Enter" to push the prompt to API. When I wanted to do this I've got so many requests that API crashed. I am really curious how to do this so if you know please let me know π
Community feedback
- @markuslewinPosted 2 months ago
Hi!
Wrapping the inputs in a form is a good approach, because it can be progressively enhanced when you're using a server-side framework (like Next and Remix):
<form className={styles.form} onSubmit={(e) => { e.preventDefault(); handleFetch(); }} > <input type="text" value={ipInput} onChange={(e) => setIpInput(e.target.value)} placeholder="Search for any IP address or domain" /> <button type="submit"> <img src="./images/icon-arrow.svg" alt="Submit" /> </button> </form>
You could also listen for key presses on the input:
<input type="text" value={ipInput} onChange={(e) => setIpInput(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") { handleFetch(); } }} placeholder="Search for any IP address or domain" />
Marked as helpful0@MikDra1Posted 2 months ago@markuslewin
Thank's for your comment! I really appreciate your help. π I also have one more question. How to make the API work when it is running on HTTP and site is running on HTTPS. Here on live site I get an error which is cause of CORS. I know there is a way with creating a proxy server but I have no idea how to do it.
0@markuslewinPosted 2 months ago@MikDra1 No problem! π
Yeah, some APIs aren't configured to be requested from the browser, and so you need to first make a request to your own server, which in-turn makes a request to the API.
Since you're using Netlify, I think the easiest way to set up a "proxy server" would be to use Netlify Functions. You essentially create a file
netlify/functions/hello.mts
containing a function that calls the API and returns the response of the API. Then, you can call that function withfetch("./netlify/functions/hello")
.I did this for another challenge. The function ended up looking like this:
export default async (req: Request) => { const body = await req.formData(); const response = await fetch("https://cleanuri.com/api/v1/shorten", { method: req.method, body, }); const json = await response.json(); return Response.json(json); };
And the caller:
export async function getShortenedUrl(link) { const body = new FormData(); body.set("url", link); const response = await fetch("/.netlify/functions/shorten", { method: "post", body, }); const json = await response.json(); return json; }
Marked as helpful0@MikDra1Posted 2 months ago@markuslewin
Thanks I've implemented some of the code but I still get some errors would you mind looking at those issues one more time, please ππ€
0@markuslewinPosted 2 months ago@MikDra1 Cool! What errors are you getting? It looks like the deployed version is working. If you want to test the function locally, you'll have to use Netlify Dev to host the function. Vite is only responsible for hosting the actual app!
Marked as helpful0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord