暂无数据
+diff --git a/.gitignore b/.gitignore index bc4414db..b057231d 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,4 @@ pnpm-debug.log* *.sln *.sw? -.history \ No newline at end of file +.history diff --git a/Dockerfile b/Dockerfile index b9d76658..2f0396b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,9 +23,9 @@ RUN npm config set registry https://registry.npmjs.org/ # 安装项目依赖 RUN cd /xiaoju-survey/web && npm install && npm run build -RUN cd /xiaoju-survey && cp -af ./web/dist/* ./server/src/apps/ui/public/ +RUN cd /xiaoju-survey && cp -af ./web/dist/* ./server/public/ -RUN cd /xiaoju-survey/server && npm install && npm run copy && npm run build +RUN cd /xiaoju-survey/server && npm install && npm run build # 暴露端口 需要跟server的port一致 EXPOSE 3000 diff --git a/docker-compose.yaml b/docker-compose.yaml index 00e22879..7eaceee8 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -16,11 +16,15 @@ services: - xiaoju-survey xiaoju-survey: - image: "xiaojusurvey/xiaoju-survey:1.0.0" + image: "xiaojusurvey/xiaoju-survey:1.0.3" container_name: xiaoju-survey restart: always ports: - "8080:3000" # API端口 + environment: + XIAOJU_SURVEY_MONGO_URL: mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@xiaoju-survey-mongo:27017 # docker-compose 会根据容器名称自动处理 + XIAOJU_SURVEY_JWT_SECRET: surveyEngineJwtSecret + XIAOJU_SURVEY_JWT_EXPIRES_IN: 8h links: - mongo:mongo depends_on: diff --git a/docker-run.sh b/docker-run.sh index 53f1f058..347a7dc3 100644 --- a/docker-run.sh +++ b/docker-run.sh @@ -1,3 +1,3 @@ #! /bin/bash cd /xiaoju-survey/server -npm run start \ No newline at end of file +npm run start:prod \ No newline at end of file diff --git a/server/.env b/server/.env new file mode 100644 index 00000000..eda5c17c --- /dev/null +++ b/server/.env @@ -0,0 +1,11 @@ +XIAOJU_SURVEY_MONGO_DB_NAME=xiaojuSurvey +XIAOJU_SURVEY_MONGO_URL=mongodb://localhost:27017 +XIAOJU_SURVEY_RESPONSE_AES_ENCRYPT_SECRET_KEY=dataAesEncryptSecretKey +XIAOJU_SURVEY_MONGO_AUTH_SOURCE= + +XIAOJU_SURVEY_HTTP_DATA_ENCRYPT_TYPE=rsa + +XIAOJU_SURVEY_JWT_SECRET=xiaojuSurveyJwtSecret +XIAOJU_SURVEY_JWT_EXPIRES_IN=8h + +XIAOJU_SURVEY_LOGGER_FILENAME=./logs/app.log \ No newline at end of file diff --git a/server/.env.development b/server/.env.development new file mode 100644 index 00000000..e69de29b diff --git a/server/.env.example b/server/.env.example deleted file mode 100644 index 4d51295f..00000000 --- a/server/.env.example +++ /dev/null @@ -1,16 +0,0 @@ -# mongo -XIAOJU_SURVEY_MONGO_URL=mongodb://localhost:27017 -XIAOJU_SURVER_MONGO_DBNAME=xiaojuSurvey - -# session -# 8 * 3600 * 1000 -XIAOJU_SURVEY_SESSION_EXPIRE_TIME=28800000 - -# encrypt -XIAOJU_SURVEY_ENCRYPT_TYPE=aes -XIAOJU_SURVEY_ENCRYPT_SECRET_KEY=dataAesEncryptSecretKey -XIAOJU_SURVEY_ENCRYPT_TYPE_LEN=10 - -# jwt -XIAOJU_SURVEY_JWT_SECRET=xiaojuSurveyJwtSecret -XIAOJU_SURVEY_JWT_EXPIRES_IN=8h \ No newline at end of file diff --git a/server/.env.production b/server/.env.production new file mode 100644 index 00000000..e69de29b diff --git a/server/.eslintrc.js b/server/.eslintrc.js new file mode 100644 index 00000000..259de13c --- /dev/null +++ b/server/.eslintrc.js @@ -0,0 +1,25 @@ +module.exports = { + parser: '@typescript-eslint/parser', + parserOptions: { + project: 'tsconfig.json', + tsconfigRootDir: __dirname, + sourceType: 'module', + }, + plugins: ['@typescript-eslint/eslint-plugin'], + extends: [ + 'plugin:@typescript-eslint/recommended', + 'plugin:prettier/recommended', + ], + root: true, + env: { + node: true, + jest: true, + }, + ignorePatterns: ['.eslintrc.js'], + rules: { + '@typescript-eslint/interface-name-prefix': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-explicit-any': 'off', + }, +}; diff --git a/server/.eslintrc.json b/server/.eslintrc.json deleted file mode 100644 index ae361159..00000000 --- a/server/.eslintrc.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "env": { - "browser": true, - "es2021": true - }, - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module" - }, - "plugins": [ - "@typescript-eslint" - ], - "rules": { - "indent": [ - "error", - 2 - ], - "linebreak-style": [ - "error", - "unix" - ], - "quotes": [ - "error", - "single" - ], - "semi": [ - "error", - "always" - ], - "space-in-parens": ["error", "never"], - "key-spacing": ["error", { "mode": "strict" }], - "comma-spacing": ["error", { "before": false, "after": true }], - "arrow-spacing": ["error", { "before": true, "after": true }], - "space-before-blocks": 2, - "object-curly-spacing": ["error", "always"] - } -} \ No newline at end of file diff --git a/server/.gitignore b/server/.gitignore index bd8a245e..286e579e 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -1,106 +1,38 @@ + +package-lock.json + +# compiled output +/dist +/node_modules + # Logs logs *.log npm-debug.log* +pnpm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json +# OS +.DS_Store -# Runtime data -pids -*.pid -*.seed -*.pid.lock +# Tests +/coverage +/.nyc_output -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ -package-lock.json - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test - -# parcel-bundler cache (https://parceljs.org/) -.cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and *not* Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# project -build/ -src/apps/question/config/env/local.ts +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json \ No newline at end of file diff --git a/server/.prettierrc b/server/.prettierrc new file mode 100644 index 00000000..dcb72794 --- /dev/null +++ b/server/.prettierrc @@ -0,0 +1,4 @@ +{ + "singleQuote": true, + "trailingComma": "all" +} \ No newline at end of file diff --git a/server/README.md b/server/README.md new file mode 100644 index 00000000..00a13b11 --- /dev/null +++ b/server/README.md @@ -0,0 +1,73 @@ +
+ +[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 +[circleci-url]: https://circleci.com/gh/nestjs/nest + +A progressive Node.js framework for building efficient and scalable server-side applications.
+ + + +## Description + +[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. + +## Installation + +```bash +$ npm install +``` + +## Running the app + +```bash +# development +$ npm run start + +# watch mode +$ npm run start:dev + +# production mode +$ npm run start:prod +``` + +## Test + +```bash +# unit tests +$ npm run test + +# e2e tests +$ npm run test:e2e + +# test coverage +$ npm run test:cov +``` + +## Support + +Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). + +## Stay in touch + +- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) +- Website - [https://nestjs.com](https://nestjs.com/) +- Twitter - [@nestframework](https://twitter.com/nestframework) + +## License + +Nest is [MIT licensed](LICENSE). diff --git a/server/nest-cli.json b/server/nest-cli.json new file mode 100644 index 00000000..f9aa683b --- /dev/null +++ b/server/nest-cli.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/nest-cli", + "collection": "@nestjs/schematics", + "sourceRoot": "src", + "compilerOptions": { + "deleteOutDir": true + } +} diff --git a/server/package.json b/server/package.json index d0b5c031..c024b0ad 100644 --- a/server/package.json +++ b/server/package.json @@ -1,52 +1,91 @@ { - "name": "survey-template", - "version": "1.0.0", - "description": "survey server template", - "main": "index.js", + "name": "server-new", + "version": "0.0.1", + "description": "", + "author": "", + "private": true, + "license": "UNLICENSED", "scripts": { - "copy": "mkdir -p ./build/ && cp -rf ./src/* ./build/", - "build": "tsc", - "start:stable": "SERVER_ENV=stable node ./build/index.js", - "start:preonline": "SERVER_ENV=preonline node ./build/index.js", - "start:online": "SERVER_ENV=online node ./build/index.js", - "start": "npm run start:online", - "local": "npx ts-node scripts/run-local.ts", - "dev": "npx ts-node-dev ./src/index.ts" - }, - "devDependencies": { - "@types/crypto-js": "^4.2.1", - "@types/koa": "^2.13.8", - "@types/koa-bodyparser": "^4.3.10", - "@types/koa-router": "^7.4.4", - "@types/koa-static": "^4.0.4", - "@typescript-eslint/eslint-plugin": "^6.15.0", - "@typescript-eslint/parser": "^6.15.0", - "cross-env": "^7.0.3", - "eslint": "^8.56.0", - "mongodb-memory-server": "^9.0.1", - "nodemon": "^2.0.20", - "ts-node": "^10.9.2", - "ts-node-dev": "^2.0.0", - "typescript": "^4.8.4" + "build": "nest build", + "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", + "local": "ts-node ./scripts/run-local.ts", + "start": "nest start", + "start:dev": "NODE_ENV=development nest start --watch", + "start:debug": "NODE_ENV=development nest start --debug --watch", + "start:prod": "NODE_ENV=production node dist/main", + "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", + "test": "NODE_ENV=development jest", + "test:watch": "NODE_ENV=development jest --watch", + "test:cov": "NODE_ENV=development jest --coverage", + "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand" }, "dependencies": { + "@nestjs/common": "^10.0.0", + "@nestjs/config": "^3.1.1", + "@nestjs/core": "^10.0.0", + "@nestjs/platform-express": "^10.0.0", + "@nestjs/serve-static": "^4.0.0", + "@nestjs/typeorm": "^10.0.1", "cheerio": "^1.0.0-rc.12", "crypto-js": "^4.2.0", - "glob": "^10.3.10", - "joi": "^17.9.2", - "jsonwebtoken": "^9.0.1", - "koa": "^2.14.2", - "koa-bodyparser": "^4.4.1", - "koa-pino-logger": "^4.0.0", - "koa-router": "^12.0.0", - "koa-static": "^4.0.3", + "dotenv": "^16.3.2", + "joi": "^17.11.0", + "jsonwebtoken": "^9.0.2", "lodash": "^4.17.21", - "moment": "^2.29.4", - "mongodb": "^5.7.0", - "svg-captcha": "^1.4.0" + "log4js": "^6.9.1", + "moment": "^2.30.1", + "mongodb": "^5.9.2", + "nanoid": "^3.3.7", + "node-forge": "^1.3.1", + "reflect-metadata": "^0.1.13", + "rxjs": "^7.8.1", + "svg-captcha": "^1.4.0", + "typeorm": "^0.3.19" }, - "engines": { - "node": ">=14.21.0", - "npm": ">=6.14.17" + "devDependencies": { + "@nestjs/cli": "^10.0.0", + "@nestjs/schematics": "^10.0.0", + "@nestjs/testing": "^10.0.0", + "@types/express": "^4.17.17", + "@types/jest": "^29.5.2", + "@types/node": "^20.3.1", + "@types/node-forge": "^1.3.11", + "@types/supertest": "^2.0.12", + "@typescript-eslint/eslint-plugin": "^6.0.0", + "@typescript-eslint/parser": "^6.0.0", + "cross-env": "^7.0.3", + "eslint": "^8.42.0", + "eslint-config-prettier": "^9.0.0", + "eslint-plugin-prettier": "^5.0.0", + "jest": "^29.5.0", + "mongodb-memory-server": "^9.1.4", + "prettier": "^3.0.0", + "source-map-support": "^0.5.21", + "supertest": "^6.3.3", + "ts-jest": "^29.1.0", + "ts-loader": "^9.4.3", + "ts-node": "^10.9.1", + "tsconfig-paths": "^4.2.0", + "typescript": "^5.1.3" + }, + "jest": { + "moduleFileExtensions": [ + "js", + "json", + "ts" + ], + "rootDir": "src", + "testRegex": ".*\\.spec\\.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + }, + "collectCoverageFrom": [ + "**/*.(t|j)s" + ], + "coverageDirectory": "../coverage", + "testEnvironment": "node", + "moduleNameMapper": { + "^src/(.*)$": "暂无数据
+(appServerName: string, params: P): Promise