-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
35 lines (29 loc) · 861 Bytes
/
index.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
import express from "express";
import cors from "cors"
import * as dotenv from 'dotenv';
dotenv.config();
import sqlRouter, { sqlDatabaseConnection } from "./src/sql_module";
import mongoDbRouter, { mongodbConnection } from "./src/mongo_module/modules";
export const app = express();
const PORT: number = parseInt(process.env.PORT || '3009');
const dataBaseType: string = process.env.DATABASE_TYPE || ""
// parsing the request data
app.use(express.json());
app.use(cors());
if (dataBaseType.toLowerCase() === "mysql") {
sqlDatabaseConnection()
app.use("/api", sqlRouter);
} else {
mongodbConnection();
app.use("/api", mongoDbRouter);
}
// App testing
app.get('/ping', (req, res) => {
res.status(200).json({
status: true,
message: "App is working",
})
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});