better-ts-stack 1.1.1 → 1.1.3
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/README.md +16 -23
- package/dist/builder/configGenerator.d.ts.map +1 -1
- package/dist/builder/configGenerator.js +5 -1
- package/dist/builder/configGenerator.js.map +1 -1
- package/dist/builder/moduleSelector.d.ts.map +1 -1
- package/dist/builder/moduleSelector.js +2 -5
- package/dist/builder/moduleSelector.js.map +1 -1
- package/dist/output/nextSteps.d.ts.map +1 -1
- package/dist/output/nextSteps.js +33 -11
- package/dist/output/nextSteps.js.map +1 -1
- package/package.json +1 -1
- package/templates/backend/express/gitignore +0 -3
- package/templates/backend/express/src/index.ts +19 -4
- package/templates/frontend/nextjs/config.json +1 -2
- package/templates/frontend/nextjs/gitignore +1 -0
- package/templates/frontend/nextjs/next.config.ts.hbs +12 -0
- package/templates/frontend/tanstack/config.json +48 -49
- package/templates/frontend/tanstack/gitignore +1 -0
- package/templates/modules/auth/express/src/controllers/authController.ts.hbs +62 -13
- package/templates/modules/auth/express/src/middleware/requireAuth.ts.hbs +26 -26
- package/templates/modules/auth/express/src/services/userStore.ts.hbs +22 -0
- package/templates/modules/docker/Dockerfile.hbs +130 -125
- package/templates/modules/docker/config.json +1 -1
- package/templates/modules/mongoose/{config.json → express/config.json} +2 -2
- package/templates/modules/mongoose/{src → express/src}/models/User.ts +48 -48
- package/templates/modules/mongoose/nextjs/config.json +16 -0
- package/templates/modules/mongoose/nextjs/lib/db.ts +36 -0
- package/templates/modules/mongoose/nextjs/models/User.ts +48 -0
- package/templates/modules/mongoose/tanstack/config.json +17 -0
- package/templates/modules/mongoose/tanstack/src/lib/db.ts +37 -0
- package/templates/modules/mongoose/tanstack/src/models/User.ts +48 -0
- package/templates/frontend/nextjs/next.config.ts +0 -8
- package/templates/modules/mongoose/src/lib/db.ts.hbs +0 -43
- /package/templates/modules/mongoose/{src → express/src}/lib/db.ts +0 -0
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# better-ts-stack
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> An interactive CLI that scaffolds TypeScript backend and full-stack projects.
|
|
4
4
|
|
|
5
|
-
`better-ts-stack`
|
|
5
|
+
`better-ts-stack` creates an Express, Next.js, or TanStack Start project with TypeScript, ESLint, and Prettier set up. Database, authentication, Docker, and git are optional.
|
|
6
6
|
|
|
7
7
|
## Quick Start
|
|
8
8
|
|
|
@@ -15,30 +15,29 @@ npm install -g better-ts-stack
|
|
|
15
15
|
better-ts-stack
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Run the command
|
|
18
|
+
Run the command and answer the prompts. The CLI creates the project folder.
|
|
19
19
|
|
|
20
20
|
## What It Can Scaffold
|
|
21
21
|
|
|
22
|
-
| Project type | Stack
|
|
23
|
-
| -------------- |
|
|
24
|
-
| Backend API | Express + TypeScript
|
|
25
|
-
| Full-stack app | Next.js 16 + React 19
|
|
22
|
+
| Project type | Stack | Optional setup |
|
|
23
|
+
| -------------- | --------------------------------------- | ------------------------------------------------------------------------ |
|
|
24
|
+
| Backend API | Express 5 + TypeScript | PostgreSQL, MongoDB, Prisma, Drizzle, Mongoose, JWT auth, Docker, git |
|
|
25
|
+
| Full-stack app | Next.js 16 or TanStack Start + React 19 | PostgreSQL, MongoDB, Prisma, Drizzle, Mongoose, Better Auth, Docker, git |
|
|
26
26
|
|
|
27
27
|
Notes:
|
|
28
28
|
|
|
29
|
-
- Express is the
|
|
30
|
-
-
|
|
31
|
-
- Better Auth is only available for full-stack projects when a database is selected.
|
|
29
|
+
- Express is the only backend framework for now. NestJS is listed in the prompt as "coming soon".
|
|
30
|
+
- Better Auth is only offered for full-stack projects that use a database.
|
|
32
31
|
|
|
33
32
|
## Interactive Prompt Flow
|
|
34
33
|
|
|
35
|
-
The CLI
|
|
36
|
-
|
|
37
|
-
You will be guided through:
|
|
34
|
+
The CLI has no subcommands or flags. It asks, in order:
|
|
38
35
|
|
|
39
36
|
1. Project name
|
|
40
37
|
2. Application type: `Backend API` or `Full-stack App`
|
|
41
|
-
3.
|
|
38
|
+
3. Framework
|
|
39
|
+
- Backend: `Express` (`NestJS` is coming soon)
|
|
40
|
+
- Full-stack: `Next.js` or `TanStack Start`
|
|
42
41
|
4. Database: `none`, `PostgreSQL`, or `MongoDB`
|
|
43
42
|
5. ORM/ODM when a database is selected
|
|
44
43
|
- PostgreSQL: `Prisma` or `Drizzle`
|
|
@@ -47,7 +46,7 @@ You will be guided through:
|
|
|
47
46
|
7. Docker setup
|
|
48
47
|
8. Authentication
|
|
49
48
|
- Express apps: JWT-based auth
|
|
50
|
-
- Next.js apps: Better Auth when a database is
|
|
49
|
+
- Next.js and TanStack Start apps: Better Auth, only when a database is selected
|
|
51
50
|
9. Git initialization
|
|
52
51
|
10. Dependency installation
|
|
53
52
|
|
|
@@ -55,14 +54,14 @@ The CLI does not ask for a port. Backend projects default to `PORT=3000`.
|
|
|
55
54
|
|
|
56
55
|
## What You Get
|
|
57
56
|
|
|
58
|
-
Every generated project includes
|
|
57
|
+
Every generated project includes:
|
|
59
58
|
|
|
60
59
|
- TypeScript with strict mode enabled
|
|
61
60
|
- ESLint and Prettier pre-configured
|
|
62
61
|
- `.env.example` and `.env` setup
|
|
63
62
|
- Ready-to-run project scripts
|
|
64
63
|
- Health check endpoint at `/health` for backend projects
|
|
65
|
-
- shadcn-compatible UI
|
|
64
|
+
- shadcn-compatible UI components for Next.js and TanStack Start projects
|
|
66
65
|
- Database wiring and schema setup when selected
|
|
67
66
|
- Authentication scaffolding when selected
|
|
68
67
|
- Docker files when selected
|
|
@@ -81,9 +80,3 @@ Every generated project includes the essentials:
|
|
|
81
80
|
## License
|
|
82
81
|
|
|
83
82
|
MIT
|
|
84
|
-
|
|
85
|
-
## Release 1.0.8
|
|
86
|
-
|
|
87
|
-
Requires Node.js 24+. Dependencies and templates use current stable releases, with TypeScript 6.0.3 held for typescript-eslint compatibility and Node.js types aligned to 24.x. Express and Next.js support PostgreSQL with Prisma or Drizzle and MongoDB with Mongoose. Prisma generation runs before builds; Docker uses Node.js 24 and Compose v2.
|
|
88
|
-
|
|
89
|
-
See [upgrade notes](https://better-ts-stack.abdullahtech.me/docs/upgrade-notes) for compatibility changes and maintainer publishing commands.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configGenerator.d.ts","sourceRoot":"","sources":["../../src/builder/configGenerator.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EAChB,MAAM,UAAU,CAAC;AAGlB,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,OAAO,EAAE,eAAe,GACvB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmBxB;AAGD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,YAAY,EAAE,EACvB,OAAO,EAAE,eAAe,GACvB,YAAY,CAuBd;AAGD,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"configGenerator.d.ts","sourceRoot":"","sources":["../../src/builder/configGenerator.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EAChB,MAAM,UAAU,CAAC;AAGlB,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,OAAO,EAAE,eAAe,GACvB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmBxB;AAGD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,YAAY,EAAE,EACvB,OAAO,EAAE,eAAe,GACvB,YAAY,CAuBd;AAGD,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,IAAI,CAAC,CAgDf;AAGD,wBAAsB,eAAe,CACnC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC,CAgCf"}
|
|
@@ -60,7 +60,11 @@ async function generatePackageJson(targetDir, mergedConfig, config) {
|
|
|
60
60
|
name: config.projectName,
|
|
61
61
|
version: "1.0.0",
|
|
62
62
|
private: true,
|
|
63
|
-
|
|
63
|
+
// TanStack's srvx static serving needs Node 24.20+ on Windows (earlier
|
|
64
|
+
// 24.x reports mismatched file stats there, so every asset 404s)
|
|
65
|
+
engines: {
|
|
66
|
+
node: config.framework === "tanstack" ? ">=24.20.0" : ">=24.0.0",
|
|
67
|
+
},
|
|
64
68
|
description: `Project created with better-ts-stack using ${config.database !== "none" ? config.database : "no database"}`,
|
|
65
69
|
...(config.framework === "tanstack" ? { type: "module" } : {}),
|
|
66
70
|
...(isFullstack ? {} : { main: "dist/index.js" }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configGenerator.js","sourceRoot":"","sources":["../../src/builder/configGenerator.ts"],"names":[],"mappings":";;;;;AAeA,wDAsBC;AAGD,kDA0BC;AAGD,
|
|
1
|
+
{"version":3,"file":"configGenerator.js","sourceRoot":"","sources":["../../src/builder/configGenerator.ts"],"names":[],"mappings":";;;;;AAeA,wDAsBC;AAGD,kDA0BC;AAGD,kDAoDC;AAGD,0CAmCC;AA/JD,2EAA2E;AAC3E,wDAA0B;AAC1B,4DAAoC;AACpC,6CAA0C;AAC1C,gDAAwB;AAExB,oCAMkB;AAElB,8DAA8D;AAC9D,SAAgB,sBAAsB,CACpC,OAA+B,EAC/B,OAAwB;IAExB,MAAM,gBAAgB,GAA2B,EAAE,CAAC;IAEpD,KAAK,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAA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AAG,GAAG,IAAI,aAAa,IAAI,CAAC;QACjD,CAAC;QAED,qBAAqB;QACrB,MAAM,cAAc,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QAC5D,MAAM,kBAAE,CAAC,SAAS,CAAC,cAAc,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;QAExD,4DAA4D;QAC5D,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC7C,MAAM,kBAAE,CAAC,SAAS,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAA,kBAAU,EACd,KAAK,EACL,gBAAgB,EAChB,sCAAsC,CACvC,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"moduleSelector.d.ts","sourceRoot":"","sources":["../../src/builder/moduleSelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa;;;YAUtB,MAAM;mBAAa,MAAM;;
|
|
1
|
+
{"version":3,"file":"moduleSelector.d.ts","sourceRoot":"","sources":["../../src/builder/moduleSelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa;;;YAUtB,MAAM;mBAAa,MAAM;;EAiBrD"}
|
|
@@ -10,12 +10,9 @@ function selectModules(config) {
|
|
|
10
10
|
? `backend/${config.framework}`
|
|
11
11
|
: `frontend/${config.framework}`;
|
|
12
12
|
const modules = [];
|
|
13
|
-
// Add database module if selected (compound ids: prisma/express,
|
|
13
|
+
// Add database module if selected (compound ids: prisma/express, drizzle/nextjs, mongoose/tanstack, ...)
|
|
14
14
|
if (config.database !== "none") {
|
|
15
|
-
|
|
16
|
-
? "mongoose"
|
|
17
|
-
: `${config.database}/${framework}`;
|
|
18
|
-
modules.push({ id: dbId, framework });
|
|
15
|
+
modules.push({ id: `${config.database}/${framework}`, framework });
|
|
19
16
|
}
|
|
20
17
|
// Add feature modules based on configuration
|
|
21
18
|
if (config.useDocker) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"moduleSelector.js","sourceRoot":"","sources":["../../src/builder/moduleSelector.ts"],"names":[],"mappings":";;AAGA,
|
|
1
|
+
{"version":3,"file":"moduleSelector.js","sourceRoot":"","sources":["../../src/builder/moduleSelector.ts"],"names":[],"mappings":";;AAGA,sCA2BC;AA5BD,mFAAmF;AACnF,SAAgB,aAAa,CAAC,MAAqB;IACjD,6CAA6C;IAC7C,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IAEnC,yCAAyC;IACzC,MAAM,IAAI,GACR,MAAM,CAAC,eAAe,KAAK,SAAS;QAClC,CAAC,CAAC,WAAW,MAAM,CAAC,SAAS,EAAE;QAC/B,CAAC,CAAC,YAAY,MAAM,CAAC,SAAS,EAAE,CAAC;IAErC,MAAM,OAAO,GAA6C,EAAE,CAAC;IAE7D,yGAAyG;IACzG,IAAI,MAAM,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;QAC/B,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,CAAC,QAAQ,IAAI,SAAS,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,6CAA6C;IAC7C,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,QAAQ,SAAS,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextSteps.d.ts","sourceRoot":"","sources":["../../src/output/nextSteps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"nextSteps.d.ts","sourceRoot":"","sources":["../../src/output/nextSteps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAmBzC,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,OAAO,GACrB,MAAM,EAAE,CAwEV;AAGD,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EAAE,GACd,MAAM,CAeR"}
|
package/dist/output/nextSteps.js
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateNextSteps = generateNextSteps;
|
|
4
4
|
exports.displayNextSteps = displayNextSteps;
|
|
5
|
+
const MONGODB_AUTH_SETUP_URL = "https://better-ts-stack.abdullahtech.me/docs/modules/database#mongoose-and-mongodb";
|
|
6
|
+
// Node 24 releases before 24.20 report mismatched file stats on Windows, which
|
|
7
|
+
// makes srvx (TanStack's production server) reject every static asset
|
|
8
|
+
const MIN_TANSTACK_WINDOWS_NODE = [24, 20];
|
|
9
|
+
function isNodeBelow([major, minor]) {
|
|
10
|
+
const [currentMajor, currentMinor] = process.versions.node
|
|
11
|
+
.split(".")
|
|
12
|
+
.map(Number);
|
|
13
|
+
return (currentMajor < major || (currentMajor === major && currentMinor < minor));
|
|
14
|
+
}
|
|
5
15
|
// Generates a list of instructions for the user to follow after project creation
|
|
6
16
|
function generateNextSteps(config, depsInstalled) {
|
|
7
17
|
const steps = [];
|
|
@@ -9,18 +19,19 @@ function generateNextSteps(config, depsInstalled) {
|
|
|
9
19
|
// Step 1: cd into project directory
|
|
10
20
|
steps.push(`cd ${config.projectName}`);
|
|
11
21
|
// Step 2: Set environment variables
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (config.useAuth) {
|
|
15
|
-
steps.push("Set BETTER_AUTH_SECRET and BETTER_AUTH_URL in .env");
|
|
16
|
-
steps.push("Visit /sign-up to create your first account");
|
|
17
|
-
}
|
|
22
|
+
if (config.database !== "none") {
|
|
23
|
+
steps.push("Review the generated .env and set your database connection details");
|
|
18
24
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
if (config.useAuth) {
|
|
26
|
+
steps.push(isFullstack
|
|
27
|
+
? "Review BETTER_AUTH_SECRET and BETTER_AUTH_URL in .env"
|
|
28
|
+
: "Review the generated JWT_SECRET in .env");
|
|
29
|
+
}
|
|
30
|
+
if (config.framework === "tanstack" &&
|
|
31
|
+
process.platform === "win32" &&
|
|
32
|
+
isNodeBelow(MIN_TANSTACK_WINDOWS_NODE)) {
|
|
33
|
+
steps.push(`Upgrade Node.js to ${MIN_TANSTACK_WINDOWS_NODE.join(".")} or newer: on Windows, ` +
|
|
34
|
+
`Node ${process.versions.node} makes "npm start" return 404 for CSS, JS, and other static files`);
|
|
24
35
|
}
|
|
25
36
|
// Step 3: Install dependencies if not already done
|
|
26
37
|
if (!depsInstalled) {
|
|
@@ -37,9 +48,20 @@ function generateNextSteps(config, depsInstalled) {
|
|
|
37
48
|
}
|
|
38
49
|
else if (config.database === "mongoose") {
|
|
39
50
|
steps.push("Ensure MongoDB is running locally or update MONGODB_URI in .env");
|
|
51
|
+
// Better Auth's MongoDB adapter uses transactions, which need a replica set
|
|
52
|
+
if (config.useAuth && isFullstack) {
|
|
53
|
+
steps.push("Better Auth uses MongoDB transactions: run MongoDB as a replica set (or use Atlas) " +
|
|
54
|
+
'and create the "user", "session", "account", and "verification" collections before signing up. ' +
|
|
55
|
+
`See ${MONGODB_AUTH_SETUP_URL}`);
|
|
56
|
+
}
|
|
40
57
|
}
|
|
41
58
|
// Step 5: Start dev server
|
|
42
59
|
steps.push(`${config.packageManager} run dev`);
|
|
60
|
+
if (config.useAuth) {
|
|
61
|
+
steps.push(isFullstack
|
|
62
|
+
? "Visit /sign-up to create your first account"
|
|
63
|
+
: "Create a user via POST /auth/register then login with /auth/login");
|
|
64
|
+
}
|
|
43
65
|
return steps;
|
|
44
66
|
}
|
|
45
67
|
// Formats the next steps into a success message string
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextSteps.js","sourceRoot":"","sources":["../../src/output/nextSteps.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"nextSteps.js","sourceRoot":"","sources":["../../src/output/nextSteps.ts"],"names":[],"mappings":";;AAmBA,8CA2EC;AAGD,4CAkBC;AAjHD,MAAM,sBAAsB,GAC1B,oFAAoF,CAAC;AAEvF,+EAA+E;AAC/E,sEAAsE;AACtE,MAAM,yBAAyB,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAE3C,SAAS,WAAW,CAAC,CAAC,KAAK,EAAE,KAAK,CAAW;IAC3C,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI;SACvD,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,MAAM,CAAC,CAAC;IACf,OAAO,CACL,YAAY,GAAG,KAAK,IAAI,CAAC,YAAY,KAAK,KAAK,IAAI,YAAY,GAAG,KAAK,CAAC,CACzE,CAAC;AACJ,CAAC;AAED,iFAAiF;AACjF,SAAgB,iBAAiB,CAC/B,MAAqB,EACrB,aAAsB;IAEtB,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,WAAW,GAAG,MAAM,CAAC,eAAe,KAAK,WAAW,CAAC;IAE3D,oCAAoC;IACpC,KAAK,CAAC,IAAI,CAA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AK,UAAU,EAAE,CAAC;QAC1C,KAAK,CAAC,IAAI,CACR,iEAAiE,CAClE,CAAC;QAEF,4EAA4E;QAC5E,IAAI,MAAM,CAAC,OAAO,IAAI,WAAW,EAAE,CAAC;YAClC,KAAK,CAAC,IAAI,CACR,qFAAqF;gBACnF,iGAAiG;gBACjG,OAAO,sBAAsB,EAAE,CAClC,CAAC;QACJ,CAAC;IACH,CAAC;IAED,2BAA2B;IAC3B,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,cAAc,UAAU,CAAC,CAAC;IAE/C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,KAAK,CAAC,IAAI,CACR,WAAW;YACT,CAAC,CAAC,6CAA6C;YAC/C,CAAC,CAAC,mEAAmE,CACxE,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,uDAAuD;AACvD,SAAgB,gBAAgB,CAC9B,YAAoB,EACpB,KAAe;IAEf,MAAM,cAAc,GAAG,KAAK;SACzB,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;SAC/C,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,OAAO,GAAG;;;;EAIhB,cAAc;;;CAGf,CAAC;IAEA,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-ts-stack",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "A powerful CLI tool that generates fully configured TypeScript projects with backend, frontend, database integration, Docker support, and more--all through an interactive setup.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -35,10 +35,25 @@ app.use((_req: Request, res: Response) => {
|
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
// Error handler
|
|
38
|
-
app.use(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
app.use(
|
|
39
|
+
(
|
|
40
|
+
err: Error & { status?: number; statusCode?: number; expose?: boolean },
|
|
41
|
+
_req: Request,
|
|
42
|
+
res: Response,
|
|
43
|
+
_next: NextFunction,
|
|
44
|
+
) => {
|
|
45
|
+
// Middleware such as express.json() sets 4xx statuses (bad JSON, body too large)
|
|
46
|
+
const status = err.status ?? err.statusCode ?? 500;
|
|
47
|
+
|
|
48
|
+
if (status >= 400 && status < 500) {
|
|
49
|
+
res.status(status).json({ error: err.expose ? err.message : 'Bad Request' });
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.error(err.stack);
|
|
54
|
+
res.status(500).json({ error: 'Internal Server Error' });
|
|
55
|
+
},
|
|
56
|
+
);
|
|
42
57
|
|
|
43
58
|
{{#if (eq database 'mongoose')}}
|
|
44
59
|
void awaitDatabase().catch((error: unknown) => {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NextConfig } from "next";
|
|
2
|
+
|
|
3
|
+
{{#if useDocker}}
|
|
4
|
+
const nextConfig: NextConfig = {
|
|
5
|
+
// Standalone output is what the Docker image runs (node server.js)
|
|
6
|
+
output: "standalone",
|
|
7
|
+
};
|
|
8
|
+
{{else}}
|
|
9
|
+
const nextConfig: NextConfig = {};
|
|
10
|
+
{{/if}}
|
|
11
|
+
|
|
12
|
+
export default nextConfig;
|
|
@@ -1,49 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "tanstack",
|
|
3
|
-
"name": "TanStack Start",
|
|
4
|
-
"description": "TanStack Start with TanStack Router, React 19, and Tailwind CSS v4",
|
|
5
|
-
"type": "base",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dev": "vite dev",
|
|
8
|
-
"build": "vite build",
|
|
9
|
-
"start": "srvx --prod -s ../client dist/server/server.js",
|
|
10
|
-
"preview": "vite preview",
|
|
11
|
-
"type:check": "tsc --noEmit",
|
|
12
|
-
"lint": "eslint src"
|
|
13
|
-
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"@tanstack/react-query": "^5.102.8",
|
|
16
|
-
"@tanstack/react-query-devtools": "^5.102.8",
|
|
17
|
-
"@tanstack/react-router": "^1.170.36",
|
|
18
|
-
"@tanstack/react-router-devtools": "^1.167.2",
|
|
19
|
-
"@tanstack/react-router-ssr-query": "^1.167.2",
|
|
20
|
-
"@tanstack/react-start": "^1.168.53",
|
|
21
|
-
"class-variance-authority": "^0.7.1",
|
|
22
|
-
"clsx": "^2.1.1",
|
|
23
|
-
"lucide-react": "^1.41.0",
|
|
24
|
-
"react": "^19.2.8",
|
|
25
|
-
"react-dom": "^19.2.8",
|
|
26
|
-
"srvx": "^1.0.4",
|
|
27
|
-
"tailwind-merge": "^3.6.0"
|
|
28
|
-
},
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"@eslint/js": "^10.0.1",
|
|
31
|
-
"@tailwindcss/vite": "^4.3.3",
|
|
32
|
-
"@types/node": "^24.13.3",
|
|
33
|
-
"@types/react": "^19.2.18",
|
|
34
|
-
"@types/react-dom": "^19.2.7",
|
|
35
|
-
"@vitejs/plugin-react": "^6.1.1",
|
|
36
|
-
"eslint": "^10.10.0",
|
|
37
|
-
"tailwindcss": "^4.3.3",
|
|
38
|
-
"typescript": "^6.0.3",
|
|
39
|
-
"typescript-eslint": "^8.69.0",
|
|
40
|
-
"vite": "^8.3.0"
|
|
41
|
-
},
|
|
42
|
-
"envVars": {
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"id": "tanstack",
|
|
3
|
+
"name": "TanStack Start",
|
|
4
|
+
"description": "TanStack Start with TanStack Router, React 19, and Tailwind CSS v4",
|
|
5
|
+
"type": "base",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite dev",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"start": "srvx --prod -s ../client dist/server/server.js",
|
|
10
|
+
"preview": "vite preview",
|
|
11
|
+
"type:check": "tsc --noEmit",
|
|
12
|
+
"lint": "eslint src"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@tanstack/react-query": "^5.102.8",
|
|
16
|
+
"@tanstack/react-query-devtools": "^5.102.8",
|
|
17
|
+
"@tanstack/react-router": "^1.170.36",
|
|
18
|
+
"@tanstack/react-router-devtools": "^1.167.2",
|
|
19
|
+
"@tanstack/react-router-ssr-query": "^1.167.2",
|
|
20
|
+
"@tanstack/react-start": "^1.168.53",
|
|
21
|
+
"class-variance-authority": "^0.7.1",
|
|
22
|
+
"clsx": "^2.1.1",
|
|
23
|
+
"lucide-react": "^1.41.0",
|
|
24
|
+
"react": "^19.2.8",
|
|
25
|
+
"react-dom": "^19.2.8",
|
|
26
|
+
"srvx": "^1.0.4",
|
|
27
|
+
"tailwind-merge": "^3.6.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@eslint/js": "^10.0.1",
|
|
31
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
32
|
+
"@types/node": "^24.13.3",
|
|
33
|
+
"@types/react": "^19.2.18",
|
|
34
|
+
"@types/react-dom": "^19.2.7",
|
|
35
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
36
|
+
"eslint": "^10.10.0",
|
|
37
|
+
"tailwindcss": "^4.3.3",
|
|
38
|
+
"typescript": "^6.0.3",
|
|
39
|
+
"typescript-eslint": "^8.69.0",
|
|
40
|
+
"vite": "^8.3.0"
|
|
41
|
+
},
|
|
42
|
+
"envVars": {
|
|
43
|
+
"PORT": "3000"
|
|
44
|
+
},
|
|
45
|
+
"templateFiles": [
|
|
46
|
+
"src/routes/index.tsx.hbs"
|
|
47
|
+
]
|
|
48
|
+
}
|
|
@@ -2,32 +2,67 @@ import { Request, Response } from "express";
|
|
|
2
2
|
import bcrypt from "bcrypt";
|
|
3
3
|
import { signToken } from "../lib/jwt";
|
|
4
4
|
import { AuthenticatedRequest } from "../middleware/requireAuth";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
createUser,
|
|
7
|
+
findUserByEmail,
|
|
8
|
+
isDuplicateEmailError,
|
|
9
|
+
toPublicUser,
|
|
10
|
+
} from "../services/userStore";
|
|
6
11
|
|
|
7
12
|
const SALT_ROUNDS = 10;
|
|
13
|
+
const MIN_PASSWORD_LENGTH = 8;
|
|
14
|
+
// bcrypt ignores bytes beyond 72, so longer passwords would be silently truncated
|
|
15
|
+
const MAX_PASSWORD_BYTES = 72;
|
|
8
16
|
|
|
17
|
+
// Request bodies are untrusted JSON, so fields may have any type
|
|
9
18
|
interface RegisterBody {
|
|
10
|
-
email?:
|
|
11
|
-
password?:
|
|
12
|
-
name?:
|
|
19
|
+
email?: unknown;
|
|
20
|
+
password?: unknown;
|
|
21
|
+
name?: unknown;
|
|
13
22
|
}
|
|
14
23
|
|
|
15
24
|
interface LoginBody {
|
|
16
|
-
email?:
|
|
17
|
-
password?:
|
|
25
|
+
email?: unknown;
|
|
26
|
+
password?: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Returns a trimmed, lowercased email, or null when the value is not a usable string
|
|
30
|
+
function normalizeEmail(email: unknown): string | null {
|
|
31
|
+
if (typeof email !== "string") return null;
|
|
32
|
+
const normalized = email.trim().toLowerCase();
|
|
33
|
+
return normalized || null;
|
|
18
34
|
}
|
|
19
35
|
|
|
20
36
|
export async function register(
|
|
21
|
-
req: Request<object, unknown, RegisterBody>,
|
|
37
|
+
req: Request<object, unknown, RegisterBody | undefined>,
|
|
22
38
|
res: Response,
|
|
23
39
|
): Promise<void> {
|
|
24
|
-
|
|
40
|
+
// Express 5 leaves req.body undefined when the request has no body
|
|
41
|
+
const body = req.body ?? {};
|
|
42
|
+
const email = normalizeEmail(body.email);
|
|
43
|
+
const password = body.password;
|
|
44
|
+
const name = body.name ?? null;
|
|
25
45
|
|
|
26
|
-
if (!email || !password) {
|
|
46
|
+
if (!email || typeof password !== "string" || !password) {
|
|
27
47
|
res.status(400).json({ error: "Email and password are required" });
|
|
28
48
|
return;
|
|
29
49
|
}
|
|
30
50
|
|
|
51
|
+
if (
|
|
52
|
+
password.length < MIN_PASSWORD_LENGTH ||
|
|
53
|
+
Buffer.byteLength(password, "utf8") > MAX_PASSWORD_BYTES
|
|
54
|
+
) {
|
|
55
|
+
res.status(400).json({
|
|
56
|
+
error: `Password must be at least ${MIN_PASSWORD_LENGTH} characters and at most ${MAX_PASSWORD_BYTES} bytes`,
|
|
57
|
+
});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (name !== null && typeof name !== "string") {
|
|
62
|
+
res.status(400).json({ error: "Name must be a string" });
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
31
66
|
const existingUser = await findUserByEmail(email);
|
|
32
67
|
if (existingUser) {
|
|
33
68
|
res.status(409).json({ error: "User already exists" });
|
|
@@ -35,19 +70,33 @@ export async function register(
|
|
|
35
70
|
}
|
|
36
71
|
|
|
37
72
|
const hashedPassword = await bcrypt.hash(password, SALT_ROUNDS);
|
|
38
|
-
|
|
73
|
+
|
|
74
|
+
let user;
|
|
75
|
+
try {
|
|
76
|
+
user = await createUser({ email, name, password: hashedPassword });
|
|
77
|
+
} catch (error) {
|
|
78
|
+
// A concurrent request registered the same email after the check above
|
|
79
|
+
if (isDuplicateEmailError(error)) {
|
|
80
|
+
res.status(409).json({ error: "User already exists" });
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
|
|
39
86
|
const token = signToken({ sub: user.id, email: user.email, name: user.name });
|
|
40
87
|
|
|
41
88
|
res.status(201).json({ user: toPublicUser(user), token });
|
|
42
89
|
}
|
|
43
90
|
|
|
44
91
|
export async function login(
|
|
45
|
-
req: Request<object, unknown, LoginBody>,
|
|
92
|
+
req: Request<object, unknown, LoginBody | undefined>,
|
|
46
93
|
res: Response,
|
|
47
94
|
): Promise<void> {
|
|
48
|
-
const
|
|
95
|
+
const body = req.body ?? {};
|
|
96
|
+
const email = normalizeEmail(body.email);
|
|
97
|
+
const password = body.password;
|
|
49
98
|
|
|
50
|
-
if (!email || !password) {
|
|
99
|
+
if (!email || typeof password !== "string" || !password) {
|
|
51
100
|
res.status(400).json({ error: "Email and password are required" });
|
|
52
101
|
return;
|
|
53
102
|
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { NextFunction, Request, Response } from 'express';
|
|
2
|
-
import { AuthTokenPayload, verifyToken } from '../lib/jwt';
|
|
3
|
-
|
|
4
|
-
export interface AuthenticatedRequest extends Request {
|
|
5
|
-
user?: AuthTokenPayload;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function requireAuth(req: AuthenticatedRequest, res: Response, next: NextFunction): void {
|
|
9
|
-
const authHeader = req.headers.authorization;
|
|
10
|
-
|
|
11
|
-
if (!authHeader || !authHeader.startsWith('Bearer')) {
|
|
12
|
-
res.status(401).json({ error: 'Authorization header missing or invalid' });
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const token = authHeader.substring('Bearer '.length);
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const payload = verifyToken(token);
|
|
20
|
-
req.user = payload;
|
|
21
|
-
next();
|
|
22
|
-
} catch (error) {
|
|
23
|
-
console.error('JWT verification failed:', error);
|
|
24
|
-
res.status(401).json({ error: 'Invalid or expired token' });
|
|
25
|
-
}
|
|
26
|
-
}
|
|
1
|
+
import { NextFunction, Request, Response } from 'express';
|
|
2
|
+
import { AuthTokenPayload, verifyToken } from '../lib/jwt';
|
|
3
|
+
|
|
4
|
+
export interface AuthenticatedRequest extends Request {
|
|
5
|
+
user?: AuthTokenPayload;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function requireAuth(req: AuthenticatedRequest, res: Response, next: NextFunction): void {
|
|
9
|
+
const authHeader = req.headers.authorization;
|
|
10
|
+
|
|
11
|
+
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
12
|
+
res.status(401).json({ error: 'Authorization header missing or invalid' });
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const token = authHeader.substring('Bearer '.length);
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const payload = verifyToken(token);
|
|
20
|
+
req.user = payload;
|
|
21
|
+
next();
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error('JWT verification failed:', error);
|
|
24
|
+
res.status(401).json({ error: 'Invalid or expired token' });
|
|
25
|
+
}
|
|
26
|
+
}
|