Colubrina/backend/index.js

76 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-06-05 22:58:18 +10:00
console.log("Initializing")
require("dotenv").config()
let express = require("express")
let app = express()
let bodyParser = require("body-parser")
let os = require("os")
app.set("trust proxy", true)
2022-08-07 00:35:00 +10:00
app.locals.config = require("./config/config.json")
2022-06-05 22:58:18 +10:00
const socket = require("./lib/socket")
2022-08-07 23:17:49 +10:00
const { User } = require("./models")
const { Op } = require("sequelize")
2022-06-05 22:58:18 +10:00
const server = require("http").createServer(app)
app.use(bodyParser.json({ limit: "15mb" }))
app.use(bodyParser.urlencoded({ extended: true }))
app.use("/api/v1/user", require("./routes/user.js"))
app.use("/api/v1/themes", require("./routes/theme.js"))
app.use("/api/v1/communications", require("./routes/communications.js"))
2022-07-29 19:20:19 +10:00
app.use("/api/v1/friends", require("./routes/friends.js"))
2022-06-05 22:58:18 +10:00
app.use("/api/v1/admin", require("./routes/admin.js"))
app.use("/usercontent", require("./routes/usercontent.js"))
app.use("/api/v1/usercontent", require("./routes/usercontent.js"))
app.use("/api/v1/mediaproxy", require("./routes/mediaproxy.js"))
2022-07-30 15:14:26 +10:00
app.use("/api/v1/associations", require("./routes/associations.js"))
2022-08-14 22:06:56 +10:00
app.use("/api/v1/polls", require("./routes/polls.js"))
2022-08-31 20:26:08 +10:00
app.use("/api/v1/feedback", require("./routes/feedback.js"))
2022-06-05 22:58:18 +10:00
app.get("/api/v1/state", async (req, res) => {
res.json({
2022-08-07 00:35:00 +10:00
release: req.app.locals.config.release,
notification: req.app.locals.config.notification,
notificationType: req.app.locals.config.notificationType,
2022-07-29 20:34:27 +10:00
latestVersion: require("../frontend/package.json").version,
2022-08-07 00:35:00 +10:00
allowRegistrations: req.app.locals.config.allowRegistrations,
publicUsers: req.app.locals.config.publicUsers,
emailVerification: req.app.locals.config.emailVerification,
rules: req.app.locals.config.rules,
name: req.app.locals.config.siteName,
loading: true,
isColubrinaServer: true
2022-06-05 22:58:18 +10:00
})
})
app.all("/api/*", (req, res) => {
res.status(404).json({
message: "Route not found."
})
})
console.log(os.hostname())
app.use(require("./lib/errorHandler"))
server.listen(23998, () => {
2022-08-07 23:17:49 +10:00
User.update(
{
status: "offline"
},
{
where: {
status: {
[Op.ne]: "offline"
}
}
}
)
2022-06-05 22:58:18 +10:00
console.log("Initialized")
console.log("Listening on port 0.0.0.0:" + 23998)
app.locals.appStarted = true
app.emit("appStarted")
})
socket.init(app, server)
module.exports = app