-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
50 lines (40 loc) · 1.29 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import express from "express";
import exphbs from "express-handlebars";
import session from "express-session";
import { fileURLToPath } from "url";
import { dirname } from "path";
// import multer from "multer";
import configRoutes from "./routes/index.js";
import middleware from "./middleware.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const staticDir = express.static(__dirname + "/public");
app.use(
session({
name: "AuthCookie",
secret: "some secret string!",
saveUninitialized: false,
resave: false,
})
);
app.use("/public", staticDir);
app.use(middleware.rewriteUnsupportedBrowserMethods);
app.use(middleware.loggingMiddleware);
app.use("/", middleware.noAuthRedirect);
app.use("/", middleware.authRedirect);
app.use(session({
name: 'AuthCookie',
secret: 'some secret string!',
resave: false,
saveUninitialized: false
}))
app.engine('handlebars', exphbs.engine({defaultLayout: 'main'}, {partialsDir: __dirname + "/views/partials"}));
app.set('view engine', 'handlebars');
configRoutes(app);
app.listen(3000, () => {
console.log("We've now got a server!");
console.log('Your routes will be running on http://localhost:3000');
});