diff --git a/src/index.ts b/src/index.ts index bf9444a..789831c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,6 +21,7 @@ export const server = fastify({ server.register(bootstrap, { directory: resolve(__dirname, "rest"), + mask: /\.rest\./, prefix: "/api" }); diff --git a/src/rest/auth.ts b/src/rest/auth.rest.ts similarity index 100% rename from src/rest/auth.ts rename to src/rest/auth.rest.ts diff --git a/src/rest/example.rest.ts b/src/rest/example.rest.ts new file mode 100644 index 0000000..ec5a142 --- /dev/null +++ b/src/rest/example.rest.ts @@ -0,0 +1,60 @@ +import { Controller, GET } from "fastify-decorators"; + +@Controller({ route: "/" }) +export default class ControllerTest { + @GET({ + url: "/hello", + options: { + schema: { + response: { + 200: { + type: "string" + } + } + } + } + }) + async helloHandler(req, res) { + if (req.query.name) { + return `Hello, ${req.query.name}!`; + } + + return "Hello world!"; + } + + @GET({ + url: "/goodbye", + options: { + schema: { + response: { + 200: { + type: "string" + } + } + } + } + }) + async goodbyeHandler(req, res) { + if (req.query.name) { + return `Goodbye, ${req.query.name}!`; + } + + return "Bye-bye!"; + } + + @GET({ + url: "/hello/:name", + options: { + schema: { + response: { + 200: { + type: "string" + } + } + } + } + }) + async nameHandler(req, res) { + return `Hello, ${req.params.name}!`; + } +}