-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
72 lines (64 loc) · 2.16 KB
/
Copy pathserver.js
File metadata and controls
72 lines (64 loc) · 2.16 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const PORT = 3000;
const express = require("express");
const path = require("path");
const mysql = require("mysql");
const dotenv = require("dotenv");
dotenv.config({ path: "./.env" });
const cookieParser = require("cookie-parser");
const hbs = require("hbs");
const app = express();
const flash = require("connect-flash");
const session = require("express-session");
const db = mysql.createConnection({
host: process.env.HOST,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE,
});
const root = __dirname; //__dirname visada yra ta direktorija kur yra jis pats iskviestas siuo atveju __dirname yra ten kur server.js failas
const backendDir = path.join(root, "backend");
const frontendDir = path.join(root, "frontend");
const staticDir = path.join(frontendDir, "static");
const routesDir = path.join(backendDir, "routes");
//Define routes
app.use(flash());
app.set("view engine", "hbs");
app.set("views", path.join(staticDir, "hbs"));
//Parse URL-encoded bodies (as sent by HTML forms)
app.use(express.urlencoded({ extend: true }));
//Parse JSON bodies (as sent by API clients)
app.use(express.json());
//naudojam cookie
app.use(cookieParser());
app.use(
session({
secret: "your secret",
resave: false,
saveUninitialized: true,
})
);
app.use(flash());
// prijungiam duomenu baze
db.connect((error) => {
if (error) {
console.log(error);
} else {
console.log("MYSQL Connected...");
}
});
module.exports = {
db: db,
};
app.use("/login", require(path.join(routesDir, "login")));
app.use("/register", require(path.join(routesDir, "register")));
app.use("/", require(path.join(routesDir, "dashboard")));
app.use("/profile", require(path.join(routesDir, "profile")));
app.use("/project", require(path.join(routesDir, "project")));
app.use("/tasks", require(path.join(routesDir, "tasks")));
app.use("/performance", require(path.join(routesDir, "performance")));
app.use("/media", express.static(path.join(staticDir, "media")));
app.use("/static", express.static(staticDir));
//nusistatom porta
app.listen(process.env.PORT || PORT, () =>
console.log("Dreamwork has started, the server is running on 3000 port")
);