Here is my question:
Is there a way to extend the response in Opine (Deno framework) in order to create custom responses?
For instance, I would like to have the ability to use:
res.success(message)
Instead of having to set HTTP codes manually each time like this:
res.setStatus(200).json({data: "success" });
I attempted to extend the response using the method shown in this link: https://deno.land/x/[email protected]/test/units/app.response.test.ts
This is the code snippet I tried:
import { opine } from "https://deno.land/x/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="046b746d6a6144362a352a#" >[email protected]</a>/mod.ts";
const app = opine();
(app.response as any).shout = function (str: string) {
this.send(str.toUpperCase());
};
app.get("/", (req, res) => {
res.shout("hello")
})
app.listen(3000);
console.log("Opine started on port 3000");
export { app };
However, when I run the program, I encounter the following error:
error: TS2339 [ERROR]: Property 'shout' does not exist on type 'OpineResponse<any>'.
res.shout("hello")
~~~~~
Your help is greatly appreciated.