Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
node_modules/
.worktrees/
.DS_Store
project.private.config.json
*.swp
backend/.main-start*.log
backend/.env
backend/.tmp-start*.log
backend/dist/
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@
2. 在微信开发者工具中,选择 **导入项目**。
3. 选择当前项目目录 (`SW`)。
4. AppID 可以填入自己的测试号或是选择“测试号”。
5. 即可在开发者工具中进行预览和调试。
5. 若需联调真实后端,先启动 `.worktrees/backend-p0/backend` 中的 NestJS 服务。
6. 即可在开发者工具中进行预览和调试。

## Backend MVP 联调

- 后端目录:`.worktrees/backend-p0/backend`
- API 地址:`http://127.0.0.1:3005`
- PostgreSQL:`localhost:5434`
- 启动顺序:
1. `docker compose up -d`
2. `npm run prisma:generate`
3. `npm run prisma:migrate -- --name mvp_baseline`
4. `npm run prisma:seed`
5. `npm run start:dev`

## 🛠 技术栈

Expand Down
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
App({
globalData: {
apiBaseUrl: 'http://127.0.0.1:3005'
},
onLaunch() {}
})
3 changes: 3 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PORT=3005
DATABASE_URL=postgresql://sw:sw@localhost:5434/sw?schema=public
TEST_USER_ID=1
12 changes: 12 additions & 0 deletions backend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
root: true,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
env: {
node: true,
jest: true,
},
extends: [],
};
4 changes: 4 additions & 0 deletions backend/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"semi": true
}
27 changes: 27 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SW Backend

NestJS backend workspace for the SW Mini Program MVP/P0 local-first backend.

## Local run

1. `docker compose up -d`
2. Copy `.env.example` to `.env` if needed
3. `npm install`
4. `npm run prisma:generate`
5. `npm run prisma:migrate -- --name mvp_baseline`
6. `npm run prisma:seed`
7. `npm run start:dev`

The backend listens on `http://127.0.0.1:3005`.
PostgreSQL is exposed on `localhost:5434`.

## Available scripts

- `npm run start:dev`
- `npm run build`
- `npm test`
- `npm run test:e2e`

## Environment

Copy `.env.example` to `.env` before running the service.
15 changes: 15 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
postgres:
image: postgres:16
container_name: sw-postgres
ports:
- '5434:5432'
environment:
POSTGRES_USER: sw
POSTGRES_PASSWORD: sw
POSTGRES_DB: sw
volumes:
- sw_postgres_data:/var/lib/postgresql/data

volumes:
sw_postgres_data:
9 changes: 9 additions & 0 deletions backend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: '.',
testRegex: '.*\\.e2e-spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
testEnvironment: 'node',
};
4 changes: 4 additions & 0 deletions backend/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
Loading