1
0
Fork 0
mirror of https://github.com/kou029w/_.git synced 2025-01-31 06:18:07 +00:00
_/fastify-validation/server.mjs

26 lines
542 B
JavaScript
Raw Normal View History

2023-09-11 17:44:55 +09:00
import fastify from "fastify";
const server = fastify({ logger: true });
server.get("/", {
schema: {
querystring: {
type: "object",
properties: { dateTime: { type: "string", format: "date-time" } },
required: ["dateTime"],
},
},
handler() {
return "ok";
},
});
// valid
await server.inject("/?dateTime=2021-09-10T15:30:00Z");
// valid
await server.inject("/?dateTime=2021-09-10T15:30:00");
// invalid: querystring/dateTime must match format "date-time"
await server.inject("/?dateTime=2021-09-10");