akf-forum/index.js

30 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-02-26 21:12:54 +03:00
const express = require('express');
const bodyParser = require('body-parser');
const path = require("path");
const fs = require("fs");
const session = require('express-session');
const error = require("./errors/error.js")
const app = express();
app.use(session({ secret: 'secret', resave: true, saveUninitialized: true }));
app.use(express.static(path.join(__dirname, "public")));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.json());
app.set('views', path.join(__dirname, 'views'));
app.set("view engine", "ejs");
//Temp:
app.get("/", (req, res) => res.redirect("/index"));
for (const type of fs.readdirSync("./routes"))
for (const file of fs.readdirSync("./routes/" + type))
app[type](`/${file.replace(".js", "")}*`, require(`./routes/${type}/${file}`))
app.get('*', (req, res) => error(res, 404, "We have not got this page."));
app.post('*', (req, res) => error(res, 404, "We have not got this page."));
const port = process.env.PORT || 3000;
app.listen(port, () => console.log("SERVER ON PORT:", port));