-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (40 loc) · 1.31 KB
/
index.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
51
import express from "express";
import path from "path";
import cookieParser from "cookie-parser";
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import {connectDB} from "./data/database.js";
import { makePostList } from "./controllers/admin.js";
import loginrouter from "./routes/login.js";
import adminRouter from "./routes/admin.js";
import portfolioRouter from "./routes/portfolio.js";
import aboutRouter from "./routes/about.js";
import contactRouter from "./routes/contact.js";
import tocRouter from "./routes/toc.js";
import formRouter from "./routes/form.js";
const app = express();
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
connectDB();
app.set("view engine","ejs");
app.use(express.static(__dirname + '/views'));
app.use(express.static(path.join("public")));
app.use(express.urlencoded({extended:true}));
app.use(cookieParser());
app.use(loginrouter);
app.use(adminRouter);
app.use(portfolioRouter);
app.use(aboutRouter);
app.use(contactRouter);
app.use(tocRouter);
app.use(formRouter);
app.get('/', async (req,res)=>{
const postList = await makePostList();
res.render('index',{postList});
});
app.use(function(req, res, next){
res.status(404).render('404');
});
app.listen(3000, ()=>{
console.log("Server is running on port 3000");
});