-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
34 lines (27 loc) · 871 Bytes
/
index.ts
File metadata and controls
34 lines (27 loc) · 871 Bytes
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
import dotenv from "dotenv";
//load env if enviroment is not equal to production
if(process.env.NODE_ENV !== "production") {
dotenv.config();
}
import express from "express";
import { engine } from "express-handlebars";
import cors from "cors";
import path from "path";
import { indexRouter } from "./routers";
const app = express();
app.use(express.urlencoded({ extended : false }));
app.use(express.json());
app.use(cors());
app.use(express.static(path.join(__dirname, "public")));
app.engine(".hbs", engine({ extname: ".hbs", defaultLayout: "main" }));
app.set("view engine", ".hbs");
app.set("views", "./views");
app.get('/', indexRouter);
app.use((req, res, next) => {
res.status(404).render("404");
});
const PORT:number|string = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log("web app running on port " + PORT)
});
export { app };