create-better-t-stack 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-better-t-stack",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "A modern CLI tool for scaffolding end-to-end type-safe TypeScript projects with best practices and customizable configurations",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -70,13 +70,12 @@ export async function createContext({ context }: CreateContextOptions) {
70
70
  }
71
71
 
72
72
  {{else if (eq backend 'express')}}
73
- import type { CreateExpressContextOptions } from "@trpc/server/adapters/express";
74
73
  {{#if auth}}
75
74
  import { fromNodeHeaders } from "better-auth/node";
76
75
  import { auth } from "./auth";
77
76
  {{/if}}
78
77
 
79
- export async function createContext(opts: CreateExpressContextOptions) {
78
+ export async function createContext(opts: any) {
80
79
  {{#if auth}}
81
80
  const session = await auth.api.getSession({
82
81
  headers: fromNodeHeaders(opts.req.headers),
@@ -7,6 +7,9 @@ import { appRouter } from "./routers/index";
7
7
  {{#if (eq api "orpc")}}
8
8
  import { RPCHandler } from "@orpc/server/node";
9
9
  import { appRouter } from "./routers";
10
+ {{#if auth}}
11
+ import { createContext } from "./lib/context";
12
+ {{/if}}
10
13
  {{/if}}
11
14
  import cors from "cors";
12
15
  import express from "express";
@@ -16,6 +19,7 @@ import { google } from "@ai-sdk/google";
16
19
  {{/if}}
17
20
  {{#if auth}}
18
21
  import { auth } from "./lib/auth";
22
+ import { toNodeHandler } from "better-auth/node";
19
23
  {{/if}}
20
24
 
21
25
  const app = express();
@@ -50,7 +54,11 @@ const handler = new RPCHandler(appRouter);
50
54
  app.use('/rpc{*path}', async (req, res, next) => {
51
55
  const { matched } = await handler.handle(req, res, {
52
56
  prefix: '/rpc',
57
+ {{#if auth}}
58
+ context: await createContext({ req }),
59
+ {{else}}
53
60
  context: {},
61
+ {{/if}}
54
62
  });
55
63
  if (matched) return;
56
64
  next();
@@ -58,9 +66,8 @@ app.use('/rpc{*path}', async (req, res, next) => {
58
66
  {{/if}}
59
67
 
60
68
  {{#if (includes examples "ai")}}
61
- // AI chat endpoint
62
69
  app.post("/ai", async (req, res) => {
63
- const { messages = [] } = req.body;
70
+ const { messages = [] } = req.body || {};
64
71
  const result = streamText({
65
72
  model: google("gemini-1.5-flash"),
66
73
  messages,
@@ -73,6 +80,7 @@ app.get("/", (_req, res) => {
73
80
  res.status(200).send("OK");
74
81
  });
75
82
 
76
- app.listen(3000, () => {
77
- console.log("Server is running on port 3000");
83
+ const port = process.env.PORT || 3000;
84
+ app.listen(port, () => {
85
+ console.log(`Server is running on port ${port}`);
78
86
  });