Обновил express до 5 версии + логгер #51

Merged
primakov merged 1 commits from update into master 2024-12-21 14:09:59 +03:00
8 changed files with 1888 additions and 1360 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ node_modules/
.env .env
.idea .idea
coverage/ coverage/
server/log/

View File

@ -1,6 +1,6 @@
FROM node:20 FROM node:20
RUN mkdir -p /usr/src/app/server/ RUN mkdir -p /usr/src/app/server/log/
WORKDIR /usr/src/app/ WORKDIR /usr/src/app/
COPY ./server /usr/src/app/server COPY ./server /usr/src/app/server

View File

@ -2,6 +2,7 @@ version: "3"
volumes: volumes:
ms_volume8: ms_volume8:
ms_logs:
services: services:
mongoDb: mongoDb:
@ -15,6 +16,8 @@ services:
# build: . # build: .
image: bro.js/ms/bh:$TAG image: bro.js/ms/bh:$TAG
restart: always restart: always
volumes:
- ms_logs:/usr/src/app/server/log
ports: ports:
- 8044:8044 - 8044:8044
environment: environment:

3080
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -23,33 +23,34 @@
"license": "MIT", "license": "MIT",
"homepage": "https://bitbucket.org/online-mentor/multi-stub#readme", "homepage": "https://bitbucket.org/online-mentor/multi-stub#readme",
"dependencies": { "dependencies": {
"axios": "^1.7.7", "axios": "^1.7.9",
"bcrypt": "^5.1.0", "bcrypt": "^5.1.1",
"body-parser": "^1.19.0", "body-parser": "^1.20.3",
"cookie-parser": "^1.4.5", "cookie-parser": "^1.4.7",
"cors": "^2.8.5",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"crypto-js": "^4.1.1", "crypto-js": "^4.2.0",
"dotenv": "^16.3.1", "dotenv": "^16.4.7",
"express": "^4.18.2", "express": "5.0.1",
"express-jwt": "^8.4.1", "express-jwt": "^8.5.1",
"express-session": "^1.17.3", "express-session": "^1.18.1",
"jsdom": "^22.1.0", "jsdom": "^25.0.1",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^9.0.2",
"mongodb": "^3.6.8", "mongodb": "^6.12.0",
"mongoose": "^8.7.1", "mongoose": "^8.9.2",
"morgan": "^1.10.0",
"pbkdf2-password": "^1.2.1", "pbkdf2-password": "^1.2.1",
"socket.io": "^4.7.1", "rotating-file-stream": "^3.2.5",
"uuid": "^9.0.0" "socket.io": "^4.8.1",
"uuid": "^11.0.3"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.12.0", "@eslint/js": "^9.17.0",
"@types/node": "18.17.1", "@types/node": "22.10.2",
"eslint": "^9.12.0", "eslint": "^9.17.0",
"globals": "^15.11.0", "globals": "^15.14.0",
"jest": "^29.7.0", "jest": "^29.7.0",
"mockingoose": "^2.16.2", "mockingoose": "^2.16.2",
"nodemon": "3.0.1", "nodemon": "3.1.9",
"supertest": "^7.0.0" "supertest": "^7.0.0"
} }
} }

View File

@ -6,6 +6,7 @@ module.exports = (err, req, res, next) => {
success: false, error: 'Токен авторизации не найден', success: false, error: 'Токен авторизации не найден',
}) })
} }
res.status(400).send({ res.status(400).send({
success: false, error: err.message || 'Что-то пошло не так', success: false, error: err.message || 'Что-то пошло не так',
}) })

View File

@ -1,57 +1,95 @@
const express = require('express') const express = require("express")
const bodyParser = require('body-parser') const bodyParser = require("body-parser")
const cookieParser = require('cookie-parser') const cookieParser = require("cookie-parser")
const session = require('express-session') const session = require("express-session")
const morgan = require("morgan")
const path = require("path")
const rfs = require("rotating-file-stream")
const app = express() const app = express()
const cors = require('cors') require("dotenv").config()
require('dotenv').config()
exports.app = app exports.app = app
const config = require('../.serverrc') const accessLogStream = rfs.createStream("access.log", {
const { setIo } = require('./io') 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.use(cookieParser())
app.options('*', cors()) app.use(
app.use(cors()) 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 server = setIo(app)
const sess = { const sess = {
secret: 'super-secret-key', secret: "super-secret-key",
resave: true, resave: true,
saveUninitialized: true, saveUninitialized: true,
cookie: { cookie: {},
},
} }
if (app.get('env') === 'production') { if (app.get("env") === "production") {
app.set('trust proxy', 1) app.set("trust proxy", 1)
sess.cookie.secure = true sess.cookie.secure = true
} }
app.use(session(sess)) app.use(session(sess))
app.use(bodyParser.json({ app.use(
limit: '50mb', bodyParser.json({
})) limit: "50mb",
app.use(bodyParser.urlencoded({ })
limit: '50mb', )
app.use(
bodyParser.urlencoded({
limit: "50mb",
extended: true, extended: true,
})) })
app.use(require('./root')) )
app.use(require("./root"))
/** /**
* Добавляйте сюда свои routers. * Добавляйте сюда свои routers.
*/ */
app.use('/kfu-m-24-1', require('./routers/kfu-m-24-1')) app.use("/kfu-m-24-1", require("./routers/kfu-m-24-1"))
app.use('/epja-2024-1', require('./routers/epja-2024-1')) app.use("/epja-2024-1", require("./routers/epja-2024-1"))
app.use('/todo', require('./routers/todo/routes')) app.use("/todo", require("./routers/todo/routes"))
app.use('/dogsitters-finder', require('./routers/dogsitters-finder')) app.use("/dogsitters-finder", require("./routers/dogsitters-finder"))
app.use('/kazan-explore', require('./routers/kazan-explore')) app.use("/kazan-explore", require("./routers/kazan-explore"))
app.use('/edateam', require('./routers/edateam-legacy')) app.use("/edateam", require("./routers/edateam-legacy"))
app.use('/dry-wash', require('./routers/dry-wash')) app.use("/dry-wash", require("./routers/dry-wash"))
app.use('/freetracker', require('./routers/freetracker')) app.use("/freetracker", require("./routers/freetracker"))
app.use('/dhs-testing', require('./routers/dhs-testing')) app.use("/dhs-testing", require("./routers/dhs-testing"))
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}`)
)

View File

@ -10,6 +10,7 @@ const folderPath = path.resolve(__dirname, './routers')
const folders = fs.readdirSync(folderPath) const folders = fs.readdirSync(folderPath)
router.get('/', async (req, res) => { router.get('/', async (req, res) => {
// throw new Error('check error message')
res.send(` res.send(`
<h1>multy stub is working v${pkg.version}</h1> <h1>multy stub is working v${pkg.version}</h1>
<ul> <ul>
@ -19,8 +20,7 @@ router.get('/', async (req, res) => {
<h2>models</h2> <h2>models</h2>
<ul>${ <ul>${
(await Promise.all( (await Promise.all(
( (await mongoose.modelNames()).map(async (name) => {
await mongoose.modelNames()).map(async (name) => {
const count = await mongoose.model(name).countDocuments() const count = await mongoose.model(name).countDocuments()
return `<li>${name} - ${count}</li>` return `<li>${name} - ${count}</li>`
} }