feat: 初始化后端和认证API
- Express.js + TypeScript - JWT认证系统 (bcryptjs加密) - Prisma ORM (SQLite/PostgreSQL) - Zod输入验证 - express-rate-limit限流 Co-Authored-By: Claude (MiniMax-M2.1) <noreply@anthropic.com>
This commit is contained in:
parent
55627762e1
commit
e35bd77e06
7
.env
7
.env
@ -7,8 +7,11 @@ JWT_SECRET=dev-secret-key-do-not-use-in-production
|
||||
JWT_EXPIRES_IN=7d
|
||||
JWT_REFRESH_EXPIRES_IN=30d
|
||||
|
||||
# Database (PostgreSQL - update with your local or Tencent Cloud credentials)
|
||||
DATABASE_URL=postgresql://qia_admin:your-password@postgres.ap-shanghai.myqcloud.com:5432/qia
|
||||
# Database (SQLite for local development, PostgreSQL for production)
|
||||
DATABASE_URL=file:./dev.db
|
||||
|
||||
# PostgreSQL (for production - Tencent Cloud)
|
||||
# DATABASE_URL=postgresql://qia_admin:your-password@postgres.ap-shanghai.myqcloud.com:5432/qia
|
||||
|
||||
# DeepSeek AI
|
||||
DEEPSEEK_API_KEY=sk-xxx
|
||||
|
||||
23
.gitignore
vendored
Normal file
23
.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# Dependencies
|
||||
node_modules/
|
||||
|
||||
# Build
|
||||
dist/
|
||||
|
||||
# Environment
|
||||
.env
|
||||
.env.local
|
||||
*.local
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Database
|
||||
*.db
|
||||
*.sqlite
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
2494
package-lock.json
generated
Normal file
2494
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -12,8 +12,10 @@
|
||||
"prisma:studio": "prisma studio"
|
||||
},
|
||||
"dependencies": {
|
||||
"@libsql/client": "^0.17.0",
|
||||
"@prisma/adapter-libsql": "^7.3.0",
|
||||
"@prisma/client": "^5.22.0",
|
||||
"bcrypt": "^5.1.1",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^4.21.0",
|
||||
@ -24,7 +26,7 @@
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bcrypt": "^5.0.2",
|
||||
"@types/bcryptjs": "^2.4.6",
|
||||
"@types/cors": "^2.8.17",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/express-rate-limit": "^6.0.0",
|
||||
|
||||
@ -6,7 +6,7 @@ generator client {
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
provider = "sqlite"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ model User {
|
||||
password_hash String
|
||||
nickname String?
|
||||
created_at DateTime @default(now())
|
||||
updated_at DateTime @updated_at
|
||||
updated_at DateTime @updatedAt
|
||||
|
||||
// Relations
|
||||
events Event[]
|
||||
@ -40,7 +40,7 @@ model Event {
|
||||
is_holiday Boolean @default(false) // Only for anniversaries
|
||||
is_completed Boolean @default(false) // Only for reminders
|
||||
created_at DateTime @default(now())
|
||||
updated_at DateTime @updated_at
|
||||
updated_at DateTime @updatedAt
|
||||
|
||||
// Relations
|
||||
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
||||
@ -57,7 +57,7 @@ model Note {
|
||||
user_id String
|
||||
content String @db.Text // HTML content from rich text editor
|
||||
created_at DateTime @default(now())
|
||||
updated_at DateTime @updated_at
|
||||
updated_at DateTime @updatedAt
|
||||
|
||||
// Relations
|
||||
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Router, Request, Response } from 'express';
|
||||
import bcrypt from 'bcrypt';
|
||||
import bcrypt from 'bcryptjs';
|
||||
import rateLimit from 'express-rate-limit';
|
||||
import { z } from 'zod';
|
||||
import prisma from '../lib/prisma';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user