-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (33 loc) · 1.12 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
//jslint esversion :6
require("dotenv").config();
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
const mongoose = require('mongoose');
app.use(cors());
app.use(express.json());
app.use(bodyParser.urlencoded({extended : false}));
mongoose.connect(process.env.MONGO_URL, {
dbName: "TRAIN_MGMT",
useNewUrlParser: true,
})
.then(() => {
console.log("Connected to MongoDB");
})
.catch((error) => {
console.error("Error connecting to MongoDB:", error);
});
const db = mongoose.connection;
db.on("error", console.error.bind(console, "MongoDB connection error:"));
const ticketRoutes = require("./routes/routes")
app.use("/api/tickets", ticketRoutes)
app.use(express.static(path.join(__dirname,"./client/angular-frontend/dist/angular-frontend")))
app.get("*",(req,res)=>{
res.sendFile(path.join(__dirname,"./client/angular-frontend/dist/angular-frontend/index.html"))
})
const port = process.env.PORT || 8080
app.listen(port ,function(){
console.log("Node Server at port " + port);
})