53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import express from "express";
|
|
import engine from "ejs-mate";
|
|
import passport from "passport";
|
|
import session from "express-session";
|
|
import flash from "connect-flash";
|
|
import dotenv from "dotenv";
|
|
dotenv.config();
|
|
|
|
import "@bot/bot";
|
|
import { setupPassport } from "@server/controllers/auth";
|
|
import { attachUser } from "@server/middleware/attachUser";
|
|
import { flashMiddleware } from "@server/middleware/flash";
|
|
import { ensureAuthenticated } from "@server/middleware/authenticated";
|
|
|
|
// import routers & middleware
|
|
import { attachGuilds } from "@server/middleware/attachGuilds";
|
|
import { router as homeRouter } from "@server/routes/home";
|
|
import { router as guildRouter } from "@server/routes/guild";
|
|
import { router as authRouter } from "@server/routes/auth";
|
|
|
|
const app = express();
|
|
|
|
app.engine("ejs", engine);
|
|
app.set("views", "./src/client/views");
|
|
app.set("view engine", "ejs");
|
|
|
|
app.use("/static", express.static("./src/client/public"));
|
|
app.use("/static/preline.js", express.static("./node_modules/preline/dist/preline.js"));
|
|
|
|
app.use(session({
|
|
secret: "unsecure-development-secret",
|
|
resave: true,
|
|
saveUninitialized: true
|
|
}));
|
|
|
|
setupPassport(passport);
|
|
app.use(passport.initialize());
|
|
app.use(passport.session());
|
|
|
|
app.use(flash());
|
|
app.use(flashMiddleware);
|
|
|
|
// register routers & middleware
|
|
app.use("/auth", authRouter);
|
|
app.use("/guild", ensureAuthenticated, attachUser, attachGuilds, guildRouter);
|
|
app.use("/", ensureAuthenticated, attachUser, attachGuilds, homeRouter);
|
|
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Server is listening on http://localhost:${PORT}`);
|
|
});
|