multy-stub/server/index.js

98 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2024-12-21 00:05:12 +03:00
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")
2023-08-01 13:14:02 +03:00
const app = express()
2024-12-21 00:05:12 +03:00
require("dotenv").config()
2024-10-16 11:06:23 +03:00
exports.app = app
2024-12-21 00:05:12 +03:00
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")
2023-08-01 13:14:02 +03:00
app.use(cookieParser())
2024-12-21 00:05:12 +03:00
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
},
})
)
2023-08-01 13:14:02 +03:00
const server = setIo(app)
const sess = {
2024-12-21 00:05:12 +03:00
secret: "super-secret-key",
resave: true,
saveUninitialized: true,
cookie: {},
2023-08-01 13:14:02 +03:00
}
2024-12-21 00:05:12 +03:00
if (app.get("env") === "production") {
app.set("trust proxy", 1)
sess.cookie.secure = true
2023-08-01 13:14:02 +03:00
}
app.use(session(sess))
2024-12-21 00:05:12 +03:00
app.use(
bodyParser.json({
limit: "50mb",
})
)
app.use(
bodyParser.urlencoded({
limit: "50mb",
2023-08-01 13:14:02 +03:00
extended: true,
2024-12-21 00:05:12 +03:00
})
)
app.use(require("./root"))
2023-08-01 13:14:02 +03:00
/**
* Добавляйте сюда свои routers.
*/
2024-12-21 00:05:12 +03:00
app.use("/kfu-m-24-1", require("./routers/kfu-m-24-1"))
app.use("/epja-2024-1", require("./routers/epja-2024-1"))
app.use("/todo", require("./routers/todo/routes"))
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"))
2024-12-24 16:34:43 +03:00
app.use("/gamehub", require("./routers/gamehub"))
2024-12-23 23:56:43 +03:00
2024-12-21 00:05:12 +03:00
app.use(require("./error"))
server.listen(config.port, () =>
console.log(`Listening on http://localhost:${config.port}`)
)