create-stackkit-app 0.4.3 → 0.4.4
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/bin/create-stackkit.js +10 -1
- package/dist/index.js +1 -0
- package/dist/lib/create-project.js +79 -539
- package/dist/lib/utils/config-utils.d.ts +2 -0
- package/dist/lib/utils/config-utils.js +33 -0
- package/dist/lib/utils/file-utils.d.ts +8 -0
- package/dist/lib/utils/file-utils.js +75 -0
- package/dist/lib/utils/git-utils.d.ts +1 -0
- package/dist/lib/utils/git-utils.js +9 -0
- package/dist/lib/utils/js-conversion.d.ts +1 -0
- package/dist/lib/utils/js-conversion.js +244 -0
- package/dist/lib/utils/module-utils.d.ts +2 -0
- package/dist/lib/utils/module-utils.js +311 -0
- package/dist/lib/utils/package-utils.d.ts +1 -0
- package/dist/lib/utils/package-utils.js +39 -0
- package/modules/auth/better-auth/files/lib/auth.ts +13 -0
- package/modules/auth/better-auth/files/schemas/prisma-schema.prisma +63 -0
- package/modules/auth/better-auth/module.json +54 -0
- package/modules/auth/clerk/module.json +115 -0
- package/modules/database/mongoose-mongodb/files/lib/db.ts +44 -6
- package/modules/database/mongoose-mongodb/files/models/User.ts +39 -0
- package/modules/database/mongoose-mongodb/module.json +27 -12
- package/modules/database/prisma/files/lib/prisma.ts +6 -0
- package/modules/database/prisma/files/prisma/schema.prisma +8 -0
- package/modules/database/prisma/files/prisma.config.ts +12 -0
- package/modules/database/prisma/module.json +140 -0
- package/package.json +7 -3
- package/templates/express/.env.example +2 -10
- package/templates/express/package.json +12 -18
- package/templates/express/src/app.ts +9 -29
- package/templates/express/src/config/env.ts +3 -14
- package/templates/express/src/features/auth/auth.controller.ts +48 -0
- package/templates/express/src/features/auth/auth.route.ts +10 -0
- package/templates/express/src/features/auth/auth.service.ts +21 -0
- package/templates/express/src/middlewares/error.middleware.ts +2 -2
- package/templates/express/src/server.ts +1 -1
- package/templates/express/template.json +1 -5
- package/templates/express/tsconfig.json +0 -1
- package/dist/lib/template-composer.d.ts +0 -16
- package/dist/lib/template-composer.js +0 -197
- package/modules/auth/better-auth-express/adapters/mongoose-mongodb.ts +0 -13
- package/modules/auth/better-auth-express/adapters/prisma-mongodb.ts +0 -15
- package/modules/auth/better-auth-express/adapters/prisma-postgresql.ts +0 -15
- package/modules/auth/better-auth-express/files/lib/auth.ts +0 -16
- package/modules/auth/better-auth-express/files/routes/auth.ts +0 -12
- package/modules/auth/better-auth-express/files/schemas/prisma-mongodb-schema.prisma +0 -72
- package/modules/auth/better-auth-express/files/schemas/prisma-postgresql-schema.prisma +0 -72
- package/modules/auth/better-auth-express/module.json +0 -61
- package/modules/auth/better-auth-nextjs/adapters/mongoose-mongodb.ts +0 -24
- package/modules/auth/better-auth-nextjs/adapters/prisma-mongodb.ts +0 -26
- package/modules/auth/better-auth-nextjs/adapters/prisma-postgresql.ts +0 -26
- package/modules/auth/better-auth-nextjs/files/lib/auth.ts +0 -26
- package/modules/auth/better-auth-nextjs/files/schemas/prisma-mongodb-schema.prisma +0 -72
- package/modules/auth/better-auth-nextjs/files/schemas/prisma-postgresql-schema.prisma +0 -72
- package/modules/auth/better-auth-nextjs/module.json +0 -62
- package/modules/auth/better-auth-react/files/lib/auth-client.ts +0 -9
- package/modules/auth/better-auth-react/module.json +0 -28
- package/modules/auth/clerk-express/module.json +0 -34
- package/modules/auth/clerk-nextjs/module.json +0 -64
- package/modules/auth/clerk-react/module.json +0 -28
- package/modules/database/prisma-mongodb/files/lib/db.ts +0 -9
- package/modules/database/prisma-mongodb/files/prisma/schema.prisma +0 -17
- package/modules/database/prisma-mongodb/module.json +0 -60
- package/modules/database/prisma-postgresql/files/lib/db.ts +0 -9
- package/modules/database/prisma-postgresql/files/prisma/schema.prisma +0 -17
- package/modules/database/prisma-postgresql/module.json +0 -60
- /package/modules/auth/{better-auth-nextjs → better-auth}/files/api/auth/[...all]/route.ts +0 -0
- /package/modules/auth/{clerk-express/files/lib → clerk/files/express}/auth.ts +0 -0
- /package/modules/auth/{clerk-nextjs/files/lib → clerk/files/nextjs}/auth-provider.tsx +0 -0
- /package/modules/auth/{clerk-nextjs/files → clerk/files/nextjs}/middleware.ts +0 -0
- /package/modules/auth/{clerk-react/files/lib → clerk/files/react}/auth-provider.tsx +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import mongoose, { Document, Schema } from "mongoose";
|
|
2
|
+
|
|
3
|
+
export interface IUser extends Document {
|
|
4
|
+
name: string;
|
|
5
|
+
email: string;
|
|
6
|
+
password: string;
|
|
7
|
+
createdAt: Date;
|
|
8
|
+
updatedAt: Date;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const UserSchema: Schema = new Schema(
|
|
12
|
+
{
|
|
13
|
+
name: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true,
|
|
16
|
+
trim: true,
|
|
17
|
+
},
|
|
18
|
+
email: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
unique: true,
|
|
22
|
+
lowercase: true,
|
|
23
|
+
trim: true,
|
|
24
|
+
},
|
|
25
|
+
password: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: true,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
timestamps: true,
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// Add indexes for better performance
|
|
36
|
+
UserSchema.index({ email: 1 });
|
|
37
|
+
UserSchema.index({ createdAt: -1 });
|
|
38
|
+
|
|
39
|
+
export default mongoose.models.User || mongoose.model<IUser>("User", UserSchema);
|
|
@@ -7,28 +7,35 @@
|
|
|
7
7
|
"database": "mongodb",
|
|
8
8
|
"supportedFrameworks": ["nextjs", "express"],
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"mongoose": "^8.8.4"
|
|
10
|
+
"mongoose": "^8.8.4",
|
|
11
|
+
"dotenv": "^17.2.3"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/mongoose": "^5.11.97"
|
|
15
|
+
},
|
|
16
|
+
"envVars": {
|
|
17
|
+
"common": [
|
|
18
|
+
{
|
|
19
|
+
"key": "DATABASE_URL",
|
|
20
|
+
"value": "mongodb://localhost:27017/myapp",
|
|
21
|
+
"description": "MongoDB connection string",
|
|
22
|
+
"required": true
|
|
23
|
+
}
|
|
24
|
+
]
|
|
11
25
|
},
|
|
12
|
-
"devDependencies": {},
|
|
13
|
-
"envVars": [
|
|
14
|
-
{
|
|
15
|
-
"key": "MONGODB_URI",
|
|
16
|
-
"value": "mongodb://localhost:27017/myapp",
|
|
17
|
-
"description": "MongoDB connection string",
|
|
18
|
-
"required": true
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
26
|
"frameworkPatches": {
|
|
22
27
|
"express": {
|
|
23
28
|
"tsconfig.json": {
|
|
24
29
|
"merge": {
|
|
25
30
|
"compilerOptions": {
|
|
31
|
+
"baseUrl": ".",
|
|
26
32
|
"paths": {
|
|
27
33
|
"@/*": ["./src/*"],
|
|
28
34
|
"@/models/*": ["./src/models/*"]
|
|
29
35
|
}
|
|
30
36
|
},
|
|
31
|
-
"include": ["src/**/*", "src/models/**/*"]
|
|
37
|
+
"include": ["src/**/*", "src/models/**/*"],
|
|
38
|
+
"exclude": ["node_modules", "dist"]
|
|
32
39
|
}
|
|
33
40
|
}
|
|
34
41
|
},
|
|
@@ -36,10 +43,12 @@
|
|
|
36
43
|
"tsconfig.json": {
|
|
37
44
|
"merge": {
|
|
38
45
|
"compilerOptions": {
|
|
46
|
+
"baseUrl": ".",
|
|
39
47
|
"paths": {
|
|
40
48
|
"@/models/*": ["./models/*"]
|
|
41
49
|
}
|
|
42
|
-
}
|
|
50
|
+
},
|
|
51
|
+
"exclude": ["node_modules", ".next", "out"]
|
|
43
52
|
}
|
|
44
53
|
}
|
|
45
54
|
}
|
|
@@ -50,6 +59,12 @@
|
|
|
50
59
|
"description": "Create MongoDB connection with Mongoose",
|
|
51
60
|
"source": "lib/db.ts",
|
|
52
61
|
"destination": "{{lib}}/db.ts"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"type": "create-file",
|
|
65
|
+
"description": "Create sample User model",
|
|
66
|
+
"source": "models/User.ts",
|
|
67
|
+
"destination": "{{models}}/User.ts"
|
|
53
68
|
}
|
|
54
69
|
]
|
|
55
70
|
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "prisma",
|
|
3
|
+
"displayName": "Prisma",
|
|
4
|
+
"description": "Prisma ORM",
|
|
5
|
+
"category": "database",
|
|
6
|
+
"provider": "prisma",
|
|
7
|
+
"supportedFrameworks": ["nextjs", "express"],
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"common": {
|
|
10
|
+
"@prisma/client": "^7.2.0",
|
|
11
|
+
"dotenv": "^17.2.3"
|
|
12
|
+
},
|
|
13
|
+
"providers": {
|
|
14
|
+
"postgresql": {
|
|
15
|
+
"@prisma/adapter-pg": "^7.2.0",
|
|
16
|
+
"pg": "^8.16.3"
|
|
17
|
+
},
|
|
18
|
+
"mongodb": {
|
|
19
|
+
"@prisma/client": "6.19"
|
|
20
|
+
},
|
|
21
|
+
"mysql": {
|
|
22
|
+
"@prisma/adapter-mariadb": "^7.2.0"
|
|
23
|
+
},
|
|
24
|
+
"sqlite": {
|
|
25
|
+
"@prisma/adapter-better-sqlite3": "^7.2.0"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"common": {
|
|
31
|
+
"prisma": "^7.2.0",
|
|
32
|
+
"tsx": "^4.21.0"
|
|
33
|
+
},
|
|
34
|
+
"providers": {
|
|
35
|
+
"postgresql": {
|
|
36
|
+
"@types/pg": "^8.16.0"
|
|
37
|
+
},
|
|
38
|
+
"mongodb": {
|
|
39
|
+
"prisma": "6.19"
|
|
40
|
+
},
|
|
41
|
+
"mysql": {},
|
|
42
|
+
"sqlite": {
|
|
43
|
+
"@types/better-sqlite3": "^7.6.13"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"envVars": {
|
|
48
|
+
"common": [
|
|
49
|
+
{
|
|
50
|
+
"key": "DATABASE_URL",
|
|
51
|
+
"value": "{{connectionString}}",
|
|
52
|
+
"description": "Database connection URL",
|
|
53
|
+
"required": true
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"providers": {
|
|
57
|
+
"mysql": [
|
|
58
|
+
{
|
|
59
|
+
"key": "DATABASE_HOST",
|
|
60
|
+
"value": "localhost",
|
|
61
|
+
"description": "MySQL host",
|
|
62
|
+
"required": true
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"key": "DATABASE_USER",
|
|
66
|
+
"value": "",
|
|
67
|
+
"description": "MySQL username",
|
|
68
|
+
"required": true
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"key": "DATABASE_PASSWORD",
|
|
72
|
+
"value": "",
|
|
73
|
+
"description": "MySQL password",
|
|
74
|
+
"required": true
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"key": "DATABASE_NAME",
|
|
78
|
+
"value": "mydb",
|
|
79
|
+
"description": "MySQL database name",
|
|
80
|
+
"required": true
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"key": "DATABASE_PORT",
|
|
84
|
+
"value": "3306",
|
|
85
|
+
"description": "MySQL port",
|
|
86
|
+
"required": false
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"frameworkPatches": {
|
|
92
|
+
"express": {
|
|
93
|
+
"tsconfig.json": {
|
|
94
|
+
"merge": {
|
|
95
|
+
"compilerOptions": {
|
|
96
|
+
"baseUrl": ".",
|
|
97
|
+
"paths": {
|
|
98
|
+
"@/*": ["./src/*"]
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"include": ["src/**/*"],
|
|
102
|
+
"exclude": ["node_modules", "dist", "prisma/migrations"]
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"nextjs": {
|
|
107
|
+
"tsconfig.json": {
|
|
108
|
+
"merge": {
|
|
109
|
+
"compilerOptions": {
|
|
110
|
+
"paths": {
|
|
111
|
+
"@/*": ["./*"]
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"exclude": ["node_modules", ".next", "out", "prisma/migrations"]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"patches": [
|
|
120
|
+
{
|
|
121
|
+
"type": "create-file",
|
|
122
|
+
"description": "Create Prisma schema",
|
|
123
|
+
"source": "prisma/schema.prisma",
|
|
124
|
+
"destination": "prisma/schema.prisma"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"type": "create-file",
|
|
128
|
+
"description": "Create Prisma config",
|
|
129
|
+
"source": "prisma.config.ts",
|
|
130
|
+
"destination": "prisma.config.ts"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"type": "create-file",
|
|
134
|
+
"description": "Create Prisma client singleton",
|
|
135
|
+
"source": "lib/prisma.ts",
|
|
136
|
+
"destination": "{{lib}}/prisma.ts"
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
"postInstall": ["npx prisma generate"]
|
|
140
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-stackkit-app",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Create a new StackKit project with modular composition",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -44,7 +44,11 @@
|
|
|
44
44
|
"fs-extra": "^11.2.0",
|
|
45
45
|
"inquirer": "^9.3.8",
|
|
46
46
|
"ora": "^5.4.1",
|
|
47
|
-
"validate-npm-package-name": "^5.0.1"
|
|
47
|
+
"validate-npm-package-name": "^5.0.1",
|
|
48
|
+
"@babel/core": "^7.28.5",
|
|
49
|
+
"@babel/preset-env": "^7.28.5",
|
|
50
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
51
|
+
"@babel/preset-react": "^7.28.5"
|
|
48
52
|
},
|
|
49
53
|
"devDependencies": {
|
|
50
54
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -58,4 +62,4 @@
|
|
|
58
62
|
"@babel/parser": "^7.28.5",
|
|
59
63
|
"@babel/plugin-transform-react-jsx": "^7.27.1"
|
|
60
64
|
}
|
|
61
|
-
}
|
|
65
|
+
}
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
+
# APP CONFIGURATION
|
|
1
2
|
PORT=3000
|
|
2
|
-
NODE_ENV=development
|
|
3
|
-
APP_URL=http://localhost:3000
|
|
4
|
-
SITE_URL=http://localhost:5173
|
|
5
|
-
|
|
6
|
-
# Proxy (set to true if running behind a proxy/load-balancer)
|
|
7
|
-
TRUST_PROXY=false
|
|
8
|
-
|
|
9
|
-
# Rate limit
|
|
10
|
-
RATE_LIMIT_MAX=100
|
|
11
|
-
RATE_LIMIT_WINDOW_MS=900000
|
|
3
|
+
NODE_ENV=development
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "my-app",
|
|
2
|
+
"name": "my-express-app",
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "tsx watch src/server.ts",
|
|
8
|
-
"clean": "rimraf dist",
|
|
9
|
-
"prebuild": "npm run clean",
|
|
10
8
|
"build": "tsc",
|
|
11
9
|
"lint": "eslint src --ext .ts",
|
|
12
10
|
"lint:fix": "eslint src --ext .ts --fix",
|
|
@@ -14,26 +12,22 @@
|
|
|
14
12
|
"start:prod": "cross-env NODE_ENV=production node dist/server.js"
|
|
15
13
|
},
|
|
16
14
|
"dependencies": {
|
|
17
|
-
"compression": "^1.7.4",
|
|
18
15
|
"cors": "^2.8.5",
|
|
19
|
-
"dotenv": "^
|
|
20
|
-
"express": "^
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"morgan": "^1.10.0"
|
|
16
|
+
"dotenv": "^17.2.3",
|
|
17
|
+
"express": "^5.2.1",
|
|
18
|
+
"helmet": "^8.1.0",
|
|
19
|
+
"morgan": "^1.10.1"
|
|
24
20
|
},
|
|
25
21
|
"devDependencies": {
|
|
26
|
-
"@types/
|
|
27
|
-
"@types/
|
|
28
|
-
"@types/
|
|
29
|
-
"@types/
|
|
30
|
-
"@types/node": "^22.10.5",
|
|
22
|
+
"@types/cors": "^2.8.19",
|
|
23
|
+
"@types/express": "^5.0.6",
|
|
24
|
+
"@types/morgan": "^1.9.10",
|
|
25
|
+
"@types/node": "^25.0.6",
|
|
31
26
|
"@typescript-eslint/eslint-plugin": "^8.52.0",
|
|
32
27
|
"@typescript-eslint/parser": "^8.52.0",
|
|
33
|
-
"cross-env": "^
|
|
28
|
+
"cross-env": "^10.1.0",
|
|
34
29
|
"eslint": "^9.39.2",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"typescript": "^5.7.2"
|
|
30
|
+
"tsx": "^4.21.0",
|
|
31
|
+
"typescript": "^5.9.3"
|
|
38
32
|
}
|
|
39
33
|
}
|
|
@@ -1,54 +1,31 @@
|
|
|
1
|
-
import compression from "compression";
|
|
2
1
|
import cors from "cors";
|
|
3
2
|
import express, { Application, NextFunction, Request, Response } from "express";
|
|
4
|
-
import rateLimit from "express-rate-limit";
|
|
5
3
|
import helmet from "helmet";
|
|
6
4
|
import morgan from "morgan";
|
|
7
5
|
import { env } from "./config/env";
|
|
6
|
+
import { authRoutes } from "./features/auth/auth.route";
|
|
8
7
|
import { errorHandler } from "./middlewares/error.middleware";
|
|
9
8
|
|
|
10
9
|
// app initialization
|
|
11
10
|
const app: Application = express();
|
|
12
11
|
app.use(express.json());
|
|
13
12
|
|
|
14
|
-
// trust proxy when behind reverse proxy (like Heroku, Vercel, Load Balancers)
|
|
15
|
-
if (env.app.trust_proxy) {
|
|
16
|
-
app.set("trust proxy", 1);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
13
|
// security headers
|
|
20
14
|
app.use(helmet());
|
|
21
15
|
|
|
22
|
-
// response compression
|
|
23
|
-
app.use(compression());
|
|
24
|
-
|
|
25
|
-
// rate limiting
|
|
26
|
-
const limiter = rateLimit({
|
|
27
|
-
windowMs: env.app.rateLimit.windowMs,
|
|
28
|
-
max: env.app.rateLimit.max,
|
|
29
|
-
standardHeaders: true,
|
|
30
|
-
legacyHeaders: false,
|
|
31
|
-
});
|
|
32
|
-
app.use(limiter);
|
|
33
|
-
|
|
34
16
|
// logging
|
|
35
|
-
if (env.
|
|
17
|
+
if (env.isProduction) {
|
|
36
18
|
app.use(morgan("combined"));
|
|
37
19
|
} else {
|
|
38
20
|
app.use(morgan("dev"));
|
|
39
21
|
}
|
|
40
22
|
|
|
41
23
|
// cors configuration
|
|
42
|
-
app.use(
|
|
43
|
-
cors({
|
|
44
|
-
origin: [env.app.site_url],
|
|
45
|
-
credentials: true,
|
|
46
|
-
}),
|
|
47
|
-
);
|
|
24
|
+
app.use(cors());
|
|
48
25
|
|
|
49
26
|
// Home page route
|
|
50
|
-
app.get("/", (
|
|
51
|
-
res.json({
|
|
27
|
+
app.get("/", (_req: Request, res: Response) => {
|
|
28
|
+
res.status(200).json({
|
|
52
29
|
title: "Welcome to your Express app",
|
|
53
30
|
description:
|
|
54
31
|
"Built with StackKit - A production-ready Express template with TypeScript, security, and best practices.",
|
|
@@ -57,8 +34,11 @@ app.get("/", (req: Request, res: Response) => {
|
|
|
57
34
|
});
|
|
58
35
|
});
|
|
59
36
|
|
|
37
|
+
// routes
|
|
38
|
+
app.use("/api/auth", authRoutes);
|
|
39
|
+
|
|
60
40
|
// unhandled routes
|
|
61
|
-
app.use((req: Request,
|
|
41
|
+
app.use((req: Request, _res: Response, next: NextFunction) => {
|
|
62
42
|
const error: any = new Error(`Can't find ${req.originalUrl} on this server!`);
|
|
63
43
|
error.status = 404;
|
|
64
44
|
|
|
@@ -4,20 +4,9 @@ import path from "path";
|
|
|
4
4
|
dotenv.config({ path: path.join(process.cwd(), ".env") });
|
|
5
5
|
|
|
6
6
|
const env = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
site_url: process.env.SITE_URL || "http://localhost:5173",
|
|
11
|
-
trust_proxy: (process.env.TRUST_PROXY || "false") === "true",
|
|
12
|
-
rateLimit: {
|
|
13
|
-
max: Number(process.env.RATE_LIMIT_MAX) || 100,
|
|
14
|
-
windowMs: Number(process.env.RATE_LIMIT_WINDOW_MS) || 15 * 60 * 1000,
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
node: {
|
|
18
|
-
env: process.env.NODE_ENV || "development",
|
|
19
|
-
isProduction: (process.env.NODE_ENV || "development") === "production",
|
|
20
|
-
},
|
|
7
|
+
port: Number(process.env.PORT) || 3000,
|
|
8
|
+
node_env: process.env.NODE_ENV || "development",
|
|
9
|
+
isProduction: (process.env.NODE_ENV || "development") === "production",
|
|
21
10
|
};
|
|
22
11
|
|
|
23
12
|
export { env };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NextFunction, Request, Response } from "express";
|
|
2
|
+
import { authServices } from "./auth.service";
|
|
3
|
+
|
|
4
|
+
const signup = async (req: Request, res: Response, next: NextFunction) => {
|
|
5
|
+
try {
|
|
6
|
+
const result = await authServices.signup(req.body);
|
|
7
|
+
|
|
8
|
+
res.status(201).json({
|
|
9
|
+
success: true,
|
|
10
|
+
message: "User registered successfully",
|
|
11
|
+
data: result,
|
|
12
|
+
});
|
|
13
|
+
} catch (error) {
|
|
14
|
+
next(error);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const signin = async (req: Request, res: Response, next: NextFunction) => {
|
|
19
|
+
try {
|
|
20
|
+
const { email, password } = req.body;
|
|
21
|
+
|
|
22
|
+
const result = await authServices.signin(email, password);
|
|
23
|
+
|
|
24
|
+
if (!result) {
|
|
25
|
+
res.status(401).json({
|
|
26
|
+
success: false,
|
|
27
|
+
message: "Invalid email or password",
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
res.status(200).json({
|
|
33
|
+
success: true,
|
|
34
|
+
message: "Login successful",
|
|
35
|
+
data: {
|
|
36
|
+
token: result.token,
|
|
37
|
+
user: result.user,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
} catch (error) {
|
|
41
|
+
next(error);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const authController = {
|
|
46
|
+
signup,
|
|
47
|
+
signin,
|
|
48
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { authController } from "./auth.controller";
|
|
3
|
+
|
|
4
|
+
const router = Router();
|
|
5
|
+
|
|
6
|
+
// routes
|
|
7
|
+
router.post("/signup", authController.signup);
|
|
8
|
+
router.post("/signin", authController.signin);
|
|
9
|
+
|
|
10
|
+
export const authRoutes = router;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
+
|
|
4
|
+
const signup = async (payload: Record<string, unknown>) => {
|
|
5
|
+
// your logic here
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const signin = async (
|
|
9
|
+
email: string,
|
|
10
|
+
password: string,
|
|
11
|
+
): Promise<{ token: string; user: any } | null> => {
|
|
12
|
+
// your logic here
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const authServices = {
|
|
17
|
+
signup,
|
|
18
|
+
signin,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type { User };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
2
|
import { env } from "../config/env";
|
|
3
3
|
|
|
4
|
-
export const errorHandler = (err: any,
|
|
4
|
+
export const errorHandler = (err: any, _req: Request, res: Response, _: NextFunction) => {
|
|
5
5
|
const statusCode = err.status || 500;
|
|
6
6
|
const errorMessage = err?.message || "Internal server error!";
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ export const errorHandler = (err: any, req: Request, res: Response, next: NextFu
|
|
|
10
10
|
message: errorMessage,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
if (!env.
|
|
13
|
+
if (!env.isProduction) {
|
|
14
14
|
payload.errors = err?.stack || err;
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
"displayName": "Express.js",
|
|
4
4
|
"framework": "express",
|
|
5
5
|
"description": "Express.js REST API with TypeScript",
|
|
6
|
-
"files": ["src/", ".
|
|
6
|
+
"files": ["src/", ".gitignore", "package.json", "tsconfig.json", ".env.example"],
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "tsx watch src/server.ts",
|
|
9
|
-
"clean": "rimraf dist",
|
|
10
|
-
"prebuild": "npm run clean",
|
|
11
9
|
"build": "tsc",
|
|
12
10
|
"lint": "eslint src --ext .ts",
|
|
13
11
|
"lint:fix": "eslint src --ext .ts --fix",
|
|
@@ -16,8 +14,6 @@
|
|
|
16
14
|
},
|
|
17
15
|
"jsScripts": {
|
|
18
16
|
"dev": "tsx --watch src/server.js",
|
|
19
|
-
"clean": "rimraf dist",
|
|
20
|
-
"prebuild": "npm run clean",
|
|
21
17
|
"build": "echo 'No build step for JavaScript'",
|
|
22
18
|
"lint": "eslint src --ext .js",
|
|
23
19
|
"lint:fix": "eslint src --ext .js --fix",
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare class TemplateComposer {
|
|
2
|
-
private templatesDir;
|
|
3
|
-
constructor(templatesDir: string);
|
|
4
|
-
/**
|
|
5
|
-
* Compose a project from base + database + auth selections
|
|
6
|
-
*/
|
|
7
|
-
compose(targetDir: string, framework: string, database: string, auth: string): Promise<void>;
|
|
8
|
-
private loadConfig;
|
|
9
|
-
private getBaseFiles;
|
|
10
|
-
private collectFiles;
|
|
11
|
-
private copyFiles;
|
|
12
|
-
private mergeConfigs;
|
|
13
|
-
private writePackageJson;
|
|
14
|
-
private writeEnvFile;
|
|
15
|
-
private getAuthKey;
|
|
16
|
-
}
|