Compare commits
170 Commits
v1.0.1
...
feat/get-m
| Author | SHA1 | Date | |
|---|---|---|---|
| bdc8d9a8e0 | |||
| e0618e431f | |||
| 1b93a8e2bb | |||
| b8dc15cbc6 | |||
|
|
949416d2a3 | ||
|
|
1ec9f1a7ec | ||
|
|
17c63e6fe0 | ||
|
|
87c1cbb19e | ||
| c86f84d037 | |||
| b8bc2c83a3 | |||
| 552457b5cb | |||
|
|
909f7e4de9 | ||
|
|
86b79a7f49 | ||
|
|
d2d8b63aba | ||
|
|
0dcf961cce | ||
|
|
38bc0c55c8 | ||
|
|
9fb4219418 | ||
|
|
fb644b6f7b | ||
|
|
d88e680413 | ||
|
|
8b7f43d15a | ||
| b9edd0091c | |||
|
|
558245f876 | ||
| a927727c1b | |||
| a9d9aa02da | |||
| e7451aea5b | |||
| 5cc580c3c5 | |||
| 3fe62ec268 | |||
| e73f7e2dc9 | |||
| 571c43c33c | |||
| 61c847b58c | |||
|
|
4d621c8bbe | ||
|
|
ab8a9ebc99 | ||
| 2d1a4ba8db | |||
| 9ed6808838 | |||
| 8bd3ccfce7 | |||
| 9818550b29 | |||
|
|
fe8a477b27 | ||
|
|
12af9b7c10 | ||
| 1871f3f96a | |||
| 05be7c4a26 | |||
|
|
46c8147172 | ||
| 271f7cab7d | |||
|
|
50e105b851 | ||
|
|
da201720c0 | ||
| b3fd86da33 | |||
| 276ef4033b | |||
|
|
a520692bc5 | ||
|
|
a327c9caeb | ||
|
|
9a8fddee3b | ||
| 149d668bea | |||
|
|
5d08c4c1c2 | ||
| 2356259823 | |||
|
|
872c921a53 | ||
| 10b5207f9a | |||
| 2ede62bcd8 | |||
| 1788f90cde | |||
| a37f7ea8a8 | |||
| 18b63bed21 | |||
| 707c3be3ec | |||
| 3d52ef9d4c | |||
| 42944af2d3 | |||
| f0f6b78cd0 | |||
|
|
7c35f17008 | ||
|
|
0208e29ae3 | ||
|
|
4d5cd104ad | ||
|
|
6702473053 | ||
| 52083097a2 | |||
| f7ac265e3b | |||
| d46841c21f | |||
| c95b015094 | |||
| 940349af29 | |||
| 268824c108 | |||
|
|
550554a7a5 | ||
| f5a8585845 | |||
| 1e67f25066 | |||
| 359a136dbf | |||
| bbc315e270 | |||
|
|
fbb5d26c8f | ||
| 9d3edcf0dd | |||
|
|
57eb548d6c | ||
|
|
34d2889c1d | ||
|
|
afc782f50f | ||
|
|
ff6e688206 | ||
|
|
4b0d9b4dbc | ||
| 2cfcd7347b | |||
| c1fe275532 | |||
| de46e9bf50 | |||
|
|
76558a7eef | ||
|
|
4bf3d662ec | ||
|
|
637939e9af | ||
|
|
02891fe301 | ||
| 6015bce32f | |||
| 528b37246b | |||
| 0c693e1bac | |||
| c77aa76645 | |||
|
|
8a0ea25029 | ||
| 6fb3f3f921 | |||
|
|
89c9d7f901 | ||
|
|
b215e22f53 | ||
|
|
f13ae33cb4 | ||
|
|
18a1095cf0 | ||
|
|
3e27c0110c | ||
| c2ada9072f | |||
| 1bd1d2b279 | |||
| 7b1ce2ae83 | |||
| de22881c28 | |||
| 20d370f120 | |||
| 85986d1844 | |||
| dccf769477 | |||
| d088ef7af8 | |||
| fad8cdfe08 | |||
| a55e6d2ab2 | |||
| eb6da8aa1b | |||
| 19a55f57c0 | |||
| b649e86a43 | |||
|
|
c53f016eec | ||
|
|
0a7cbc3434 | ||
|
|
279650db25 | ||
| 2d45b4af72 | |||
| bd4de9d7ba | |||
| 10dbe5c147 | |||
| 435f17ee22 | |||
| 677dc3dc29 | |||
| 88e3fe4172 | |||
| 21dcc8bbec | |||
| 4778dba7ed | |||
| 07a02ade1f | |||
| 311846f92d | |||
| ebd561098f | |||
| b4372eb53a | |||
| bdb6b4ca3e | |||
| 426cb70eb6 | |||
| 61441e21b8 | |||
| a6f61ba033 | |||
| 8588a7fa38 | |||
| c35185ea32 | |||
| 78a332732d | |||
| 5f54355b97 | |||
| 4efbb56905 | |||
| 50c6286190 | |||
| de29da93ba | |||
| 7cdd7e790f | |||
| 569b1b0d9e | |||
| 272961c583 | |||
| 63284d6c08 | |||
| cb56e2dd2c | |||
| 325e2f125b | |||
| 786085d4d0 | |||
| c95a00fb19 | |||
| 95373069da | |||
| b8275a4c8f | |||
| fb868bfefc | |||
| 086c94c58a | |||
| 812a95dd85 | |||
| 85ee64e92b | |||
|
|
eb87f400ee | ||
| 92cabfa048 | |||
|
|
b2a853e183 | ||
|
|
0a6d50cb60 | ||
| 7809806b83 | |||
|
|
1aa0c36c84 | ||
|
|
7c3132c54b | ||
| 8fc85a7de8 | |||
|
|
cb8b2cc5aa | ||
| 6651215eeb | |||
| 80f8cef142 | |||
|
|
5a57291523 | ||
|
|
39ab269f07 | ||
| 7cb23080bf | |||
| d74e4a8624 |
45
.eslintrc.js
@@ -1,45 +0,0 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
commonjs: true,
|
||||
es2021: true,
|
||||
},
|
||||
extends: [
|
||||
'airbnb-base',
|
||||
],
|
||||
parserOptions: {
|
||||
ecmaVersion: 12,
|
||||
},
|
||||
rules: {
|
||||
indent: ['error', 4],
|
||||
semi: ['warn', 'never'],
|
||||
'object-curly-newline': ['warn', {
|
||||
ObjectExpression: 'always',
|
||||
ObjectPattern: {
|
||||
multiline: true,
|
||||
},
|
||||
ImportDeclaration: 'never',
|
||||
ExportDeclaration: {
|
||||
multiline: true, minProperties: 3,
|
||||
},
|
||||
}],
|
||||
'consistent-return': [0],
|
||||
'prefer-const': [0],
|
||||
'no-unused-vars': [0],
|
||||
'no-console': [0],
|
||||
'global-require': [0],
|
||||
'no-plusplus': [0],
|
||||
'no-underscore-dangle': [0],
|
||||
'import/no-dynamic-require': [0],
|
||||
'no-shadow': ['warn'],
|
||||
'no-restricted-syntax': ['warn'],
|
||||
'max-len': ['warn'],
|
||||
'linebreak-style': [0],
|
||||
'prefer-destructuring': [0],
|
||||
'imoprt-order': [0],
|
||||
'no-param-reassign': [1],
|
||||
'no-await-in-loop': [1],
|
||||
'no-return-assign': [1],
|
||||
'spaced-comment': [1],
|
||||
},
|
||||
}
|
||||
4
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
node_modules/
|
||||
.env
|
||||
.idea
|
||||
.idea
|
||||
coverage/
|
||||
server/log/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
port: 8044,
|
||||
port: process.env.PORT ?? 8044,
|
||||
mongoAddr: process.env.MONGO_ADDR || 'localhost',
|
||||
mongoPort: 27017,
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
FROM 'node:18'
|
||||
FROM node:20
|
||||
|
||||
RUN mkdir -p /usr/src/app/server/
|
||||
RUN mkdir -p /usr/src/app/server/log/
|
||||
WORKDIR /usr/src/app/
|
||||
|
||||
COPY ./server /usr/src/app/server
|
||||
COPY ./package.json /usr/src/app/package.json
|
||||
COPY ./package-lock.json /usr/src/app/package-lock.json
|
||||
COPY ./.serverrc.js /usr/src/app/.serverrc.js
|
||||
# COPY ./.env /usr/src/app/.env
|
||||
|
||||
RUN npm i --only=prod
|
||||
# RUN npm i --omit=dev
|
||||
RUN npm ci
|
||||
EXPOSE 8044
|
||||
|
||||
CMD ["npm", "run", "up:prod"]
|
||||
|
||||
16
Jenkinsfile
vendored
@@ -1,7 +1,7 @@
|
||||
pipeline {
|
||||
agent {
|
||||
docker {
|
||||
image 'node:18'
|
||||
image 'node:20'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ pipeline {
|
||||
steps {
|
||||
sh 'node -v'
|
||||
sh 'npm -v'
|
||||
sh 'npm install'
|
||||
sh 'npm ci'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,16 +22,16 @@ pipeline {
|
||||
|
||||
stage('test') {
|
||||
steps {
|
||||
sh 'npm run test:start'
|
||||
sh 'npm run test'
|
||||
}
|
||||
}
|
||||
|
||||
stage('clean-all') {
|
||||
stage('archiving') {
|
||||
steps {
|
||||
sh 'rm -rf .[!.]*'
|
||||
sh 'rm -rf ./*'
|
||||
sh 'ls -a'
|
||||
script {
|
||||
archiveArtifacts artifacts: 'coverage/*/**'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
docker stop ms-mongo
|
||||
docker volume remove ms_volume
|
||||
docker volume create ms_volume
|
||||
docker run --rm -v ms_volume:/data/db --name ms-mongo -p 27017:27017 -d mongo:4.4.13
|
||||
docker run --rm -v ms_volume:/data/db --name ms-mongo -p 27017:27017 -d mongo:8.0.3
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
version: "3"
|
||||
|
||||
volumes:
|
||||
ms_volume:
|
||||
ms_volume8:
|
||||
ms_logs:
|
||||
|
||||
services:
|
||||
mongoDb:
|
||||
image: mongo:4.4.13
|
||||
image: mongo:8.0.3
|
||||
volumes:
|
||||
- ms_volume:/data/db
|
||||
- ms_volume8:/data/db
|
||||
restart: always
|
||||
# ports:
|
||||
# - 27017:27017
|
||||
multy-stubs:
|
||||
build: .
|
||||
# build: .
|
||||
image: bro.js/ms/bh:$TAG
|
||||
restart: always
|
||||
volumes:
|
||||
- ms_logs:/usr/src/app/server/log
|
||||
ports:
|
||||
- 8044:8044
|
||||
environment:
|
||||
|
||||
16
eslint.config.mjs
Normal file
@@ -0,0 +1,16 @@
|
||||
import globals from "globals";
|
||||
import pluginJs from "@eslint/js";
|
||||
|
||||
|
||||
export default [
|
||||
{ ignores: ['server/routers/old/*'] },
|
||||
{ files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } },
|
||||
{ languageOptions: { globals: globals.node } },
|
||||
pluginJs.configs.recommended,
|
||||
{
|
||||
rules: {
|
||||
semi: ['warn', 'never'],
|
||||
'no-unused-vars': [0],
|
||||
}
|
||||
}
|
||||
];
|
||||
201
jest.config.js
Normal file
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* For a detailed explanation regarding each configuration property, visit:
|
||||
* https://jestjs.io/docs/configuration
|
||||
*/
|
||||
|
||||
/** @type {import('jest').Config} */
|
||||
const config = {
|
||||
// All imported modules in your tests should be mocked automatically
|
||||
// automock: false,
|
||||
|
||||
// Stop running tests after `n` failures
|
||||
// bail: 0,
|
||||
|
||||
// The directory where Jest should store its cached dependency information
|
||||
// cacheDirectory: "C:\\Users\\alex\\AppData\\Local\\Temp\\jest",
|
||||
|
||||
// Automatically clear mock calls, instances, contexts and results before every test
|
||||
clearMocks: true,
|
||||
|
||||
// Indicates whether the coverage information should be collected while executing the test
|
||||
collectCoverage: true,
|
||||
|
||||
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
||||
collectCoverageFrom: [
|
||||
"<rootDir>/server/routers/**/*.js"
|
||||
],
|
||||
|
||||
// The directory where Jest should output its coverage files
|
||||
coverageDirectory: "coverage",
|
||||
|
||||
// An array of regexp pattern strings used to skip coverage collection
|
||||
coveragePathIgnorePatterns: [
|
||||
"\\\\node_modules\\\\",
|
||||
"<rootDir>/server/routers/old"
|
||||
],
|
||||
|
||||
// Indicates which provider should be used to instrument code for coverage
|
||||
coverageProvider: "v8",
|
||||
|
||||
// A list of reporter names that Jest uses when writing coverage reports
|
||||
// coverageReporters: [
|
||||
// "json",
|
||||
// "text",
|
||||
// "lcov",
|
||||
// "clover"
|
||||
// ],
|
||||
|
||||
// An object that configures minimum threshold enforcement for coverage results
|
||||
// coverageThreshold: undefined,
|
||||
|
||||
// A path to a custom dependency extractor
|
||||
// dependencyExtractor: undefined,
|
||||
|
||||
// Make calling deprecated APIs throw helpful error messages
|
||||
// errorOnDeprecated: false,
|
||||
|
||||
// The default configuration for fake timers
|
||||
// fakeTimers: {
|
||||
// "enableGlobally": false
|
||||
// },
|
||||
|
||||
// Force coverage collection from ignored files using an array of glob patterns
|
||||
// forceCoverageMatch: [],
|
||||
|
||||
// A path to a module which exports an async function that is triggered once before all test suites
|
||||
// globalSetup: undefined,
|
||||
|
||||
// A path to a module which exports an async function that is triggered once after all test suites
|
||||
// globalTeardown: undefined,
|
||||
|
||||
// A set of global variables that need to be available in all test environments
|
||||
// globals: {},
|
||||
|
||||
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
||||
// maxWorkers: "50%",
|
||||
|
||||
// An array of directory names to be searched recursively up from the requiring module's location
|
||||
// moduleDirectories: [
|
||||
// "node_modules"
|
||||
// ],
|
||||
|
||||
// An array of file extensions your modules use
|
||||
// moduleFileExtensions: [
|
||||
// "js",
|
||||
// "mjs",
|
||||
// "cjs",
|
||||
// "jsx",
|
||||
// "ts",
|
||||
// "tsx",
|
||||
// "json",
|
||||
// "node"
|
||||
// ],
|
||||
|
||||
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
||||
// moduleNameMapper: {},
|
||||
|
||||
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
||||
// modulePathIgnorePatterns: [],
|
||||
|
||||
// Activates notifications for test results
|
||||
// notify: false,
|
||||
|
||||
// An enum that specifies notification mode. Requires { notify: true }
|
||||
// notifyMode: "failure-change",
|
||||
|
||||
// A preset that is used as a base for Jest's configuration
|
||||
// preset: undefined,
|
||||
|
||||
// Run tests from one or more projects
|
||||
// projects: undefined,
|
||||
|
||||
// Use this configuration option to add custom reporters to Jest
|
||||
// reporters: undefined,
|
||||
|
||||
// Automatically reset mock state before every test
|
||||
// resetMocks: false,
|
||||
|
||||
// Reset the module registry before running each individual test
|
||||
// resetModules: false,
|
||||
|
||||
// A path to a custom resolver
|
||||
// resolver: undefined,
|
||||
|
||||
// Automatically restore mock state and implementation before every test
|
||||
// restoreMocks: false,
|
||||
|
||||
// The root directory that Jest should scan for tests and modules within
|
||||
// rootDir: undefined,
|
||||
|
||||
// A list of paths to directories that Jest should use to search for files in
|
||||
// roots: [
|
||||
// "<rootDir>"
|
||||
// ],
|
||||
|
||||
// Allows you to use a custom runner instead of Jest's default test runner
|
||||
// runner: "jest-runner",
|
||||
|
||||
// The paths to modules that run some code to configure or set up the testing environment before each test
|
||||
// setupFiles: [],
|
||||
|
||||
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
||||
// setupFilesAfterEnv: [],
|
||||
|
||||
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
||||
// slowTestThreshold: 5,
|
||||
|
||||
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
||||
// snapshotSerializers: [],
|
||||
|
||||
// The test environment that will be used for testing
|
||||
// testEnvironment: "jest-environment-node",
|
||||
|
||||
// Options that will be passed to the testEnvironment
|
||||
// testEnvironmentOptions: {},
|
||||
|
||||
// Adds a location field to test results
|
||||
// testLocationInResults: false,
|
||||
|
||||
// The glob patterns Jest uses to detect test files
|
||||
// testMatch: [
|
||||
// "**/__tests__/**/*.[jt]s?(x)",
|
||||
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
||||
// ],
|
||||
|
||||
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
||||
// testPathIgnorePatterns: [
|
||||
// "\\\\node_modules\\\\"
|
||||
// ],
|
||||
|
||||
// The regexp pattern or array of patterns that Jest uses to detect test files
|
||||
// testRegex: [],
|
||||
|
||||
// This option allows the use of a custom results processor
|
||||
// testResultsProcessor: undefined,
|
||||
|
||||
// This option allows use of a custom test runner
|
||||
// testRunner: "jest-circus/runner",
|
||||
|
||||
// A map from regular expressions to paths to transformers
|
||||
// transform: undefined,
|
||||
|
||||
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
||||
// transformIgnorePatterns: [
|
||||
// "\\\\node_modules\\\\",
|
||||
// "\\.pnp\\.[^\\\\]+$"
|
||||
// ],
|
||||
|
||||
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
||||
// unmockedModulePathPatterns: undefined,
|
||||
|
||||
// Indicates whether each individual test should be reported during the run
|
||||
verbose: true,
|
||||
|
||||
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
||||
// watchPathIgnorePatterns: [],
|
||||
|
||||
// Whether to use watchman for file crawling
|
||||
// watchman: true,
|
||||
};
|
||||
|
||||
module.exports = config;
|
||||
7479
package-lock.json
generated
59
package.json
@@ -1,19 +1,18 @@
|
||||
{
|
||||
"name": "multi-stub",
|
||||
"version": "1.0.1",
|
||||
"version": "1.1.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "npx nodemon ./server",
|
||||
"start": "cross-env PORT=8033 npx nodemon ./server",
|
||||
"up:prod": "cross-env NODE_ENV=\"production\" node ./server",
|
||||
"deploy:d:stop": "docker-compose down",
|
||||
"deploy:d:build": "docker-compose build",
|
||||
"deploy:d:up": "docker-compose up -d",
|
||||
"deploy:d:stop": "docker compose down",
|
||||
"deploy:d:build": "docker compose build",
|
||||
"deploy:d:up": "docker compose up -d",
|
||||
"redeploy": "npm run deploy:d:stop && npm run deploy:d:build && npm run deploy:d:up",
|
||||
"eslint": "npx eslint ./server",
|
||||
"eslint:fix": "npx eslint ./server --fix",
|
||||
"test": "echo \"test complete\"",
|
||||
"test:start": "start-server-and-test up:prod 8044 test"
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -24,30 +23,34 @@
|
||||
"license": "MIT",
|
||||
"homepage": "https://bitbucket.org/online-mentor/multi-stub#readme",
|
||||
"dependencies": {
|
||||
"bcrypt": "^5.1.0",
|
||||
"body-parser": "^1.19.0",
|
||||
"cookie-parser": "^1.4.5",
|
||||
"cors": "^2.8.5",
|
||||
"axios": "^1.7.9",
|
||||
"bcrypt": "^5.1.1",
|
||||
"body-parser": "^1.20.3",
|
||||
"cookie-parser": "^1.4.7",
|
||||
"cross-env": "^7.0.3",
|
||||
"crypto-js": "^4.1.1",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"express-jwt": "^8.4.1",
|
||||
"express-session": "^1.17.3",
|
||||
"jsdom": "^22.1.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mongodb": "^3.6.8",
|
||||
"mysql": "^2.18.1",
|
||||
"crypto-js": "^4.2.0",
|
||||
"dotenv": "^16.4.7",
|
||||
"express": "5.0.1",
|
||||
"express-jwt": "^8.5.1",
|
||||
"express-session": "^1.18.1",
|
||||
"jsdom": "^25.0.1",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"mongodb": "^6.12.0",
|
||||
"mongoose": "^8.9.2",
|
||||
"morgan": "^1.10.0",
|
||||
"pbkdf2-password": "^1.2.1",
|
||||
"socket.io": "^4.7.1",
|
||||
"start-server-and-test": "^1.13.1",
|
||||
"uuid": "^9.0.0"
|
||||
"rotating-file-stream": "^3.2.5",
|
||||
"socket.io": "^4.8.1",
|
||||
"uuid": "^11.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "18.17.1",
|
||||
"eslint": "8.46.0",
|
||||
"eslint-config-airbnb-base": "15.0.0",
|
||||
"eslint-plugin-import": "2.28.0",
|
||||
"nodemon": "3.0.1"
|
||||
"@eslint/js": "^9.17.0",
|
||||
"@types/node": "22.10.2",
|
||||
"eslint": "^9.17.0",
|
||||
"globals": "^15.14.0",
|
||||
"jest": "^29.7.0",
|
||||
"mockingoose": "^2.16.2",
|
||||
"nodemon": "3.1.9",
|
||||
"supertest": "^7.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
16
server/__tests__/__snapshots__/todo.test.js.snap
Normal file
@@ -0,0 +1,16 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`todo list app get list 1`] = `
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"_id": "670f69b5796ce7a9069da2f7",
|
||||
"created": "2024-10-16T07:22:29.042Z",
|
||||
"id": "670f69b5796ce7a9069da2f7",
|
||||
"items": [],
|
||||
"title": "qqq",
|
||||
},
|
||||
],
|
||||
"success": true,
|
||||
}
|
||||
`;
|
||||
34
server/__tests__/todo.test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const { describe, it, expect } = require('@jest/globals')
|
||||
const request = require('supertest')
|
||||
const express = require('express')
|
||||
const mockingoose = require('mockingoose')
|
||||
const { ListModel } = require('../data/model/todo/list')
|
||||
|
||||
const todo = require('../routers/todo/routes')
|
||||
|
||||
const app = express()
|
||||
app.use(todo)
|
||||
|
||||
const listExample = {
|
||||
"title": "qqq",
|
||||
"items": [],
|
||||
"_id": "670f69b5796ce7a9069da2f7",
|
||||
"created": "2024-10-16T07:22:29.042Z",
|
||||
"id": "670f69b5796ce7a9069da2f7"
|
||||
}
|
||||
|
||||
describe('todo list app', () => {
|
||||
it('get list', (done) => {
|
||||
mockingoose(ListModel)
|
||||
.toReturn([listExample], 'find')
|
||||
.toReturn(listExample, 'create')
|
||||
|
||||
request(app)
|
||||
.get('/list')
|
||||
.expect(200)
|
||||
.then((response) => {
|
||||
expect(response.body).toMatchSnapshot()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -6,6 +6,7 @@ module.exports = (err, req, res, next) => {
|
||||
success: false, error: 'Токен авторизации не найден',
|
||||
})
|
||||
}
|
||||
|
||||
res.status(400).send({
|
||||
success: false, error: err.message || 'Что-то пошло не так',
|
||||
})
|
||||
|
||||
123
server/index.js
@@ -1,66 +1,97 @@
|
||||
const express = require('express')
|
||||
const bodyParser = require('body-parser')
|
||||
const cookieParser = require('cookie-parser')
|
||||
const session = require('express-session')
|
||||
const express = require("express")
|
||||
const bodyParser = require("body-parser")
|
||||
const cookieParser = require("cookie-parser")
|
||||
const session = require("express-session")
|
||||
const morgan = require("morgan")
|
||||
const path = require("path")
|
||||
const rfs = require("rotating-file-stream")
|
||||
|
||||
const app = express()
|
||||
const cors = require('cors')
|
||||
require('dotenv').config()
|
||||
require("dotenv").config()
|
||||
exports.app = app
|
||||
|
||||
const config = require('../.serverrc')
|
||||
const { setIo } = require('./io')
|
||||
const accessLogStream = rfs.createStream("access.log", {
|
||||
size: "10M",
|
||||
interval: "1d",
|
||||
compress: "gzip",
|
||||
path: path.join(__dirname, "log"),
|
||||
})
|
||||
|
||||
const errorLogStream = rfs.createStream("error.log", {
|
||||
size: "10M",
|
||||
interval: "1d",
|
||||
compress: "gzip",
|
||||
path: path.join(__dirname, "log"),
|
||||
})
|
||||
|
||||
const config = require("../.serverrc")
|
||||
const { setIo } = require("./io")
|
||||
|
||||
app.use(cookieParser())
|
||||
app.options('*', cors())
|
||||
app.use(cors())
|
||||
app.use(
|
||||
morgan("combined", {
|
||||
stream: accessLogStream,
|
||||
skip: function (req, res) {
|
||||
return res.statusCode >= 400
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
// log all requests to access.log
|
||||
app.use(
|
||||
morgan("combined", {
|
||||
stream: errorLogStream,
|
||||
skip: function (req, res) {
|
||||
console.log('statusCode', res.statusCode, res.statusCode <= 400)
|
||||
return res.statusCode < 400
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
const server = setIo(app)
|
||||
|
||||
const sess = {
|
||||
secret: 'super-secret-key',
|
||||
resave: true,
|
||||
saveUninitialized: true,
|
||||
cookie: {
|
||||
},
|
||||
secret: "super-secret-key",
|
||||
resave: true,
|
||||
saveUninitialized: true,
|
||||
cookie: {},
|
||||
}
|
||||
if (app.get('env') === 'production') {
|
||||
app.set('trust proxy', 1)
|
||||
sess.cookie.secure = true
|
||||
if (app.get("env") === "production") {
|
||||
app.set("trust proxy", 1)
|
||||
sess.cookie.secure = true
|
||||
}
|
||||
app.use(session(sess))
|
||||
|
||||
app.use(bodyParser.json({
|
||||
limit: '50mb',
|
||||
}))
|
||||
app.use(bodyParser.urlencoded({
|
||||
limit: '50mb',
|
||||
app.use(
|
||||
bodyParser.json({
|
||||
limit: "50mb",
|
||||
})
|
||||
)
|
||||
app.use(
|
||||
bodyParser.urlencoded({
|
||||
limit: "50mb",
|
||||
extended: true,
|
||||
}))
|
||||
app.use(require('./root'))
|
||||
})
|
||||
)
|
||||
app.use(require("./root"))
|
||||
|
||||
/**
|
||||
* Добавляйте сюда свои routers.
|
||||
*/
|
||||
app.use('/lobsters', require('./routers/lobsters'))
|
||||
app.use('/example', require('./routers/example'))
|
||||
// app.use('/coder', require('./routers/coder'))
|
||||
//app.use('/stc-21-03', require('./routers/stc-21-03'))
|
||||
//app.use('/stc-21', require('./routers/stc'))
|
||||
//app.use('/stc-22-24', require('./routers/stc-22-24'))
|
||||
// app.use('/bushou-api', require('./routers/bushou'))
|
||||
app.use("/kfu-m-24-1", require("./routers/kfu-m-24-1"))
|
||||
app.use("/epja-2024-1", require("./routers/epja-2024-1"))
|
||||
app.use("/v1/todo", require("./routers/todo"))
|
||||
app.use("/dogsitters-finder", require("./routers/dogsitters-finder"))
|
||||
app.use("/kazan-explore", require("./routers/kazan-explore"))
|
||||
app.use("/edateam", require("./routers/edateam-legacy"))
|
||||
app.use("/dry-wash", require("./routers/dry-wash"))
|
||||
app.use("/freetracker", require("./routers/freetracker"))
|
||||
app.use("/dhs-testing", require("./routers/dhs-testing"))
|
||||
app.use("/gamehub", require("./routers/gamehub"))
|
||||
|
||||
// app.use('/uryndyklar-api', require('./routers/uryndyklar'))
|
||||
// app.use('/neptunium', require('./routers/neptunium'))
|
||||
// app.use('/music-learn', require('./routers/music-learn'))
|
||||
// app.use('/publicium', require('./routers/publicium'))
|
||||
// app.use('/task-boss', require('./routers/task-boss'))
|
||||
// app.use('/car-wash', require('./routers/car-wash'))
|
||||
app.use('/zoom-bar', require('./routers/zoom-bar'))
|
||||
//app.use('/basket', require('./routers/basket'))
|
||||
//app.use('/easy-project', require('./routers/easy-project'))
|
||||
//app.use('/sugarbun', require('./routers/sugarbun'))
|
||||
app.use('/epja-2023-2', require('./routers/epja-2023-2'))
|
||||
require('./routers/hub-video')
|
||||
|
||||
app.use(require('./error'))
|
||||
app.use(require("./error"))
|
||||
|
||||
server.listen(config.port, () => console.log(`Listening on http://localhost:${config.port}`))
|
||||
server.listen(config.port, () =>
|
||||
console.log(`Listening on http://localhost:${config.port}`)
|
||||
)
|
||||
|
||||
@@ -1,17 +1,32 @@
|
||||
const router = require('express').Router()
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const router = require('express').Router()
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const pkg = require('../package.json')
|
||||
|
||||
require('./utils/mongoose')
|
||||
const folderPath = path.resolve(__dirname, './routers')
|
||||
const folders = fs.readdirSync(folderPath)
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.send(`
|
||||
router.get('/', async (req, res) => {
|
||||
// throw new Error('check error message')
|
||||
res.send(`
|
||||
<h1>multy stub is working v${pkg.version}</h1>
|
||||
<ul>
|
||||
${folders.map((f) => `<li>${f}</li>`).join('')}
|
||||
</ul>
|
||||
|
||||
<h2>models</h2>
|
||||
<ul>${
|
||||
(await Promise.all(
|
||||
(await mongoose.modelNames()).map(async (name) => {
|
||||
const count = await mongoose.model(name).countDocuments()
|
||||
return `<li>${name} - ${count}</li>`
|
||||
}
|
||||
)
|
||||
)).map(t => t).join(' ')
|
||||
}</ul>
|
||||
`)
|
||||
})
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 377 B |
|
Before Width: | Height: | Size: 470 B |
|
Before Width: | Height: | Size: 578 B |
|
Before Width: | Height: | Size: 481 B |
|
Before Width: | Height: | Size: 368 B |
|
Before Width: | Height: | Size: 593 B |
|
Before Width: | Height: | Size: 539 B |
|
Before Width: | Height: | Size: 414 B |
|
Before Width: | Height: | Size: 414 B |
|
Before Width: | Height: | Size: 739 B |
|
Before Width: | Height: | Size: 686 B |
|
Before Width: | Height: | Size: 750 B |
|
Before Width: | Height: | Size: 687 B |
|
Before Width: | Height: | Size: 706 B |
|
Before Width: | Height: | Size: 776 B |
|
Before Width: | Height: | Size: 628 B |
|
Before Width: | Height: | Size: 742 B |
|
Before Width: | Height: | Size: 853 B |
|
Before Width: | Height: | Size: 911 B |
|
Before Width: | Height: | Size: 601 B |
|
Before Width: | Height: | Size: 648 B |
|
Before Width: | Height: | Size: 709 B |
|
Before Width: | Height: | Size: 442 B |
|
Before Width: | Height: | Size: 858 B |
|
Before Width: | Height: | Size: 718 B |
|
Before Width: | Height: | Size: 1015 B |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 811 B |
|
Before Width: | Height: | Size: 872 B |
|
Before Width: | Height: | Size: 659 B |
|
Before Width: | Height: | Size: 767 B |
|
Before Width: | Height: | Size: 719 B |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 812 B |
|
Before Width: | Height: | Size: 760 B |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 955 B |
|
Before Width: | Height: | Size: 908 B |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1016 B |
|
Before Width: | Height: | Size: 997 B |
|
Before Width: | Height: | Size: 856 B |
|
Before Width: | Height: | Size: 693 B |
|
Before Width: | Height: | Size: 711 B |
|
Before Width: | Height: | Size: 766 B |
|
Before Width: | Height: | Size: 952 B |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 843 B |
|
Before Width: | Height: | Size: 951 B |
|
Before Width: | Height: | Size: 967 B |
|
Before Width: | Height: | Size: 923 B |
|
Before Width: | Height: | Size: 725 B |
|
Before Width: | Height: | Size: 935 B |
|
Before Width: | Height: | Size: 820 B |
|
Before Width: | Height: | Size: 841 B |
|
Before Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1006 B |
|
Before Width: | Height: | Size: 949 B |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 930 B |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 782 B |
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 855 B |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 809 B |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 837 B |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 760 B |
|
Before Width: | Height: | Size: 1020 B |
|
Before Width: | Height: | Size: 1015 B |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |