akf-forum/index.js

20 lines
738 B
JavaScript
Raw Normal View History

2022-03-22 00:10:29 +03:00
const error = require("./errors/error.js");
const session = require('express-session');
2022-03-13 16:16:46 +03:00
const bodyParser = require('body-parser');
2022-03-22 00:10:29 +03:00
const express = require('express');
2022-03-13 16:16:46 +03:00
const fs = require("fs");
const app = express();
app.use(session({ secret: 'secret', resave: true, saveUninitialized: true }));
app.use(bodyParser.urlencoded({ extended: true }));
2022-03-22 00:10:29 +03:00
app.use(express.static("public"));
2022-03-13 16:16:46 +03:00
app.set("view engine", "ejs");
2022-03-22 00:10:29 +03:00
app.use(express.json());
2022-03-13 16:16:46 +03:00
2022-03-22 00:10:29 +03:00
for (const file of fs.readdirSync("./routes"))
app.use("/" + file.slice(0, -3), require(`./routes/${file}`));
2022-03-21 23:53:22 +03:00
2022-03-22 00:10:29 +03:00
app.all("*", (req, res) => error(res, 404, "We have not got this page."));
2022-03-21 23:53:22 +03:00
2022-03-13 16:16:46 +03:00
const port = process.env.PORT || 3000;
2022-03-22 00:10:29 +03:00
app.listen(port, () => console.log("Akf-forum on port:", port));