-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (38 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
40
41
42
43
44
45
46
47
48
49
50
const serverless = require("serverless-http"); // Lambda
const dotenv = require("dotenv");
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const mongoose = require("mongoose");
dotenv.config();
const dataSource = require("./models/appDataSource");
const routes = require("./routes");
// mysql
const initializeDataSource = async () => {
try {
await dataSource.initialize();
console.log("Data Source has been initialized!");
} catch (error) {
console.error(`Initialize Error: ${error}`);
}
};
initializeDataSource();
// mongoDB
// mongoose
// .connect("mongodb://localhost:27017/assignment3")
// .then(() => console.log("MongoDB connected"))
// .catch((err) => console.log(err));
const app = express();
app.use(express.json());
app.use(cors());
app.use(morgan("dev"));
app.use(routes);
app.get("/ping", (req, res) => {
return res.status(200).json({ message: "pong" });
});
const PORT = process.env.PORT;
const start = async () => {
app.listen(PORT, () => console.log(`server is listening on ${PORT}`));
};
start();
module.exports.handler = serverless(app);