No big news from me again — just enjoying the summer with my family and prepping some fresh content for you. In this issue, you'll find a handy Nuxt tip on validating data in your server routes. Hope you enjoy it!
👉🏻 Learn how to make a simple to-do app with Nuxt.
👉🏻 Instead of manually defining server routes and fetching them on the client, the author uses Prim+RPC to define functions on Nuxt's server and simply call those functions directly from the client.
👉🏻 Focus on building your product and not worry about setting up auth, database, infrastructure, payments, and more.
💡 Nuxt Tip: Validate Data in Your Server Routes
When you are working with Nuxt server routes, you should always validate the data that you receive from the client before processing it.
This is important to ensure that your application is secure and that you are not vulnerable to attacks such as SQL injection or cross-site scripting. Additionally, validating your data can help you catch errors early on and prevent them from causing issues later on in your application.
Luckily, h3 provides a simple and powerful way to validate data in your Nuxt server routes.
h3 is the H(TTP) server framework which is used by Nitro, which is the server engine used in Nuxt 3+.
It provides the following utility methods to help you validate your data:
getValidatedQuery to validate query parameters
getValidatedRouterParams to validate route parameters
readValidatedBody to validate the request body
h3 allows you to use the validation library of your choice like Zod, Yup, or Joi to validate your data.
For this example, we will use Zod to validate the data in our Nuxt server routes with the following schema:
1import { z } from 'zod';23const productSchema = z.object({4 name: z.string().min(3).max(20),5 id: z.number({ coerce: true }).positive().int(),6});
Let's see how we can use these validation utils to validate query parameters in our Nuxt server routes. Therefore, you can use the getValidatedQuery method provided by h3 instead of getQuery. This method takes the schema that you want to validate the query parameters against and returns the validated query parameters:
How's it going? I was planning to release the update for Reusable Components yesterday, but things haven't gone as planned. Instead, I will be launching it next week. I need a just a bit more time to make sure that the quality is up to my standards. As I've been updating the course and re-writing all the content and step-by-step refactorings, I've also been able to simplify a few things. It's just like refactoring a piece of code, and it's one of the greatest feelings. I also looked at how much content is in there, and it looks like it will be similar to the Clean Components Toolkit. Lots of great content on how to write highly reusable components, simplified and updated — I can't wait to release the update next week! Oh, and one more thing: I'm doing a podcast with Alex Lichter ! It's called Deja Vue and we'll be releasing the first ...
Monday, November 20, 2023 I'd pay $10K up front # Matt Mullenweg : "Sales of the 100-year plan so far: 0. Hundreds of people filled out the form, though. I think we really messed something up in the follow-up, including not making it self-serve to start. Will review and try again. It's an important promise to us." # I'm very much a customer for this service. It would be worth $10K for to buy 100 years of persistence for my web writing. A simple easy to understand service that helps get the process started. # I transfer scripting.com to Automattic as registrar. # I upload the contents from S3 to Automattic server. Static files, HTML, feeds, images, code. # Automattic provides an API to keep the files updated and so I can add to them as long as I'm still writing. # The files are publicly accessible over HTTP. # Automattic agrees to renew the domain for 100 years, and manage access to the files, with reasona...
评论
发表评论