forked from samifouad/trpc-deno-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
32 lines (25 loc) · 861 Bytes
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { opine } from "https://deno.land/x/opine@2.3.3/mod.ts";
import * as trpc from "https://esm.sh/@trpc/server@9.27.2";
import * as trpcExpress from "https://esm.sh/@trpc/server@9.27.2/adapters/express";
//import { opineCors } from "https://deno.land/x/cors@v1.2.2/mod.ts";
const app = opine(); // opine is express ported to deno
const port = 5005;
// setup tRPC router
const appRouter = trpc.router().query("hw", {
resolve() {
const data = { hello: "world" };
return data;
},
});
// apply tRPC router as a middleware
app.use(
"/trpc",
trpcExpress.createExpressMiddleware({
router: appRouter,
createContext: () => null,
}),
);
//app.use(opineCors()); // uncomment to use cors
app.listen(port); // start server
console.log(`Opine started on port: ${port}`);
export type AppRouter = typeof appRouter; // tRPC type-only export