-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
78 lines (70 loc) · 2.02 KB
/
app.ts
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
73
74
75
76
77
78
import { createConnection } from "typeorm";
import { Request, Response, NextFunction } from "express";
import { User } from "./src/Entities/User";
import { Tile } from "./src/Entities/Tile";
import { Grout } from "./src/Entities/Grout";
import { AllGroutRoute } from "./src/routes/Grout";
import { AllTilesRoute } from "./src/routes/Tiles";
import { AllProductsRoute } from "./src/routes/products";
import { UserRoutes } from "./src/routes/User";
import express from "express";
import bodyParser from "body-parser";
import multerMiddleware from "./src/middlewares/multer-config";
import { Role } from "./src/Entities/Role";
const app = express();
//connecting to database
let connection;
const main = async () => {
try {
connection = await createConnection({
type: "postgres",
host: "localhost",
port: 5432,
username: "postgres",
password: "bcsf20m538",
database: "inventory",
entities: [User, Role, Tile, Grout],
synchronize: true,
});
console.log("connected to postgres");
app.listen(9000, () => console.log("running on port 9000"));
} catch {
console.log("connection failed");
}
};
main();
//setting headers for CORS (Cross server resource share)
app.use((req: Request, res: any, next: NextFunction) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Methods",
"GET",
"POST",
"PUT",
"PATCH",
"DELETE",
"OPTIONS"
);
res.setHeader(
"Access-Control-Allow-Headers",
"Access-Control-Allow-Headers, Content-Type,Authorization"
);
next();
});
//body-parser middleware
app.use(bodyParser.json());
//multer for file parsing
app.use(multerMiddleware);
//app or api routes
app.use(AllProductsRoute);
app.use(AllTilesRoute);
app.use(AllGroutRoute);
app.use(UserRoutes);
export { connection };
// getConnection()
// .createQueryBuilder()
// .select("user")
// .from(User, "user")
// .leftJoinAndSelect("user.role", "Role")
// .where("user.UserName = :UserName", { UserName: req.body.UserName })
// .getOne();