-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (34 loc) · 1.1 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
import "./dotenv.js";
import express from "express";
import routes from "./routes/index.js";
import sequelize from "./config/sequelize.js";
import cors from "cors";
import path from "path";
import fileDirName from './config/file-dir-name.js';
import { engine } from 'express-handlebars'
const { __dirname, __filename } = fileDirName(import.meta);
const app = express();
const PORT = 3000;
// Definindo dir root project global
global.__basedir = __dirname;
// Setup Template Engine
app.engine("hbs", engine({
extname: ".hbs",
defaultLayout: "main",
partialsDir: path.join(__dirname, "views/partials"),
layoutsDir: path.join(__dirname, "views/layouts"),
}))
app.set("view engine", "hbs");
app.set("views", path.join(__dirname, "views"));
// Definindo static folder
app.use(express.static(path.join(__dirname, "public")));
// MIDDLEWARE
app.use(cors());
app.use(express.json());
// ROTAS
app.use("/", routes);
// Conexão com Banco de Dados
sequelize.sync().then(() => {
console.log("Conectado ao Banco de Dados com sucesso!");
});
app.listen(PORT, () => console.log("Servidor rodando na porta " + PORT));