-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (44 loc) · 1.41 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
51
52
53
54
55
if (process.env.NODE_ENV !== "production") {
require("dotenv").config();
}
const express = require("express");
const connectDb = require("./@helpers/db");
const cors = require("cors");
const { register } = require("./controllers/auth.controller");
const { verifyApiKey } = require("./middlewares/basic_auth");
const businessRouter = require("./routes/business.router");
const planRouter = require("./routes/plan.router");
const app = express();
connectDb();
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(cors());
const api_version = "v1";
app.post(`/${api_version}/auth/signup`, register);
app.use(verifyApiKey);
app.get(`/${api_version}`, (req, res, next) => {
return res.status(200).json({
status: "success",
message: "Welcome to Startup Plan APIService v1",
});
})
app.use(`/${api_version}/businesses`, businessRouter);
app.use(`/${api_version}/plans`, planRouter);
//error middleware
app.use((error, req, res, next) => {
const statusCode = error.statusCode ? error.statusCode : 500;
let message = error.message;
if (statusCode == 500) {
message = "An error occurred on our server, we have been notified";
}
res.status(statusCode).json({
status: "error",
message: message,
error_code: statusCode,
data: null
});
})
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Startup Plan APIService is running on port ${PORT}`)
})