2022-03-24 17:57:40 -04:00
|
|
|
import * as express from "express"
|
|
|
|
import * as bodyParser from "body-parser"
|
|
|
|
import * as errorhandler from "strong-error-handler"
|
2022-03-28 15:13:22 -04:00
|
|
|
import { posts, users, auth, files, admin } from "@routes/index"
|
2022-03-24 17:57:40 -04:00
|
|
|
import { errors } from "celebrate"
|
2022-03-24 21:03:57 -04:00
|
|
|
import secretKey from "@lib/middleware/secret-key"
|
|
|
|
import markdown from "@lib/render-markdown"
|
2022-03-06 19:46:59 -05:00
|
|
|
|
2022-03-24 17:57:40 -04:00
|
|
|
export const app = express()
|
2022-03-06 19:46:59 -05:00
|
|
|
|
2022-03-24 17:57:40 -04:00
|
|
|
app.use(bodyParser.urlencoded({ extended: true }))
|
|
|
|
app.use(bodyParser.json({ limit: "5mb" }))
|
2022-03-06 19:46:59 -05:00
|
|
|
|
2022-03-10 02:46:59 -05:00
|
|
|
app.use("/auth", auth)
|
2022-03-06 19:46:59 -05:00
|
|
|
app.use("/posts", posts)
|
2022-03-10 02:46:59 -05:00
|
|
|
app.use("/users", users)
|
2022-03-11 21:48:40 -05:00
|
|
|
app.use("/files", files)
|
2022-03-28 15:13:22 -04:00
|
|
|
app.use("/admin", admin)
|
2022-03-06 19:46:59 -05:00
|
|
|
|
2022-03-25 17:31:10 -04:00
|
|
|
app.get("/welcome", secretKey, (req, res) => {
|
|
|
|
const introContent = process.env.WELCOME_CONTENT
|
|
|
|
const introTitle = process.env.WELCOME_TITLE
|
|
|
|
if (!introContent || !introTitle) {
|
|
|
|
return res.status(500).json({ error: "Missing welcome content" })
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.json({
|
|
|
|
title: introTitle,
|
|
|
|
content: introContent,
|
|
|
|
rendered: markdown(introContent)
|
|
|
|
})
|
2022-03-24 21:03:57 -04:00
|
|
|
})
|
|
|
|
|
2022-03-24 17:57:40 -04:00
|
|
|
app.use(errors())
|
2022-03-24 17:53:57 -04:00
|
|
|
|
2022-03-24 17:57:40 -04:00
|
|
|
app.use(
|
2022-03-25 17:31:10 -04:00
|
|
|
errorhandler({
|
2022-03-28 19:19:53 -04:00
|
|
|
debug: process.env.NODE_ENV !== "production",
|
2022-03-25 17:31:10 -04:00
|
|
|
log: true
|
|
|
|
})
|
2022-03-24 17:57:40 -04:00
|
|
|
)
|