Skip to content

Commit 54a66c4

Browse files
janekhuongtektaxi
authored andcommitted
API routing for getStatusCount function
1 parent 4bc9f5f commit 54a66c4

File tree

5 files changed

+213
-132
lines changed

5 files changed

+213
-132
lines changed

app.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const Services = {
88
log: require("./services/logger.service"),
99
db: require("./services/database.service"),
1010
auth: require("./services/auth.service"),
11-
env: require("./services/env.service")
11+
env: require("./services/env.service"),
1212
};
1313

1414
const envLoadResult = Services.env.load(path.join(__dirname, "./.env"));
@@ -31,6 +31,7 @@ const searchRouter = require("./routes/api/search");
3131
const settingsRouter = require("./routes/api/settings");
3232
const volunteerRouter = require("./routes/api/volunteer");
3333
const roleRouter = require("./routes/api/role");
34+
const emailsRouter = require("./routes/api/emails");
3435

3536
const app = express();
3637
Services.db.connect();
@@ -40,42 +41,40 @@ let corsOptions = {};
4041
if (!Services.env.isProduction()) {
4142
corsOptions = {
4243
origin: [`http://${process.env.FRONTEND_ADDRESS_DEV}`],
43-
credentials: true
44+
credentials: true,
4445
};
4546
} else {
4647
corsOptions = {
4748
origin: (origin, callback) => {
4849
const allowedOrigins = [
4950
`https://${process.env.FRONTEND_ADDRESS_DEPLOY}`,
5051
`https://${process.env.FRONTEND_ADDRESS_BETA}`,
51-
`https://docs.mchacks.ca`
52+
`https://docs.mchacks.ca`,
5253
];
5354

5455
const regex = /^https:\/\/dashboard-[\w-]+\.vercel\.app$/;
5556

5657
if (
5758
allowedOrigins.includes(origin) || // Explicitly allowed origins
58-
regex.test(origin) // Matches dashboard subdomains
59+
regex.test(origin) // Matches dashboard subdomains
5960
) {
6061
callback(null, true);
6162
} else {
62-
callback(new Error('Not allowed by CORS'));
63+
callback(new Error("Not allowed by CORS"));
6364
}
6465
},
65-
credentials: true
66+
credentials: true,
6667
};
6768
}
6869

69-
70-
7170
app.use(cors(corsOptions));
7271
app.use(Services.log.requestLogger);
7372
app.use(Services.log.errorLogger);
7473
app.use(express.json());
7574
app.use(
7675
express.urlencoded({
77-
extended: false
78-
})
76+
extended: false,
77+
}),
7978
);
8079
app.use(cookieParser());
8180
//Cookie-based session tracking
@@ -86,8 +85,8 @@ app.use(
8685
// Cookie Options
8786
maxAge: 48 * 60 * 60 * 1000, //Logged in for 48 hours
8887
sameSite: process.env.COOKIE_SAME_SITE,
89-
secureProxy: !Services.env.isTest()
90-
})
88+
secureProxy: !Services.env.isTest(),
89+
}),
9190
);
9291
app.use(passport.initialize());
9392
app.use(passport.session()); //persistent login session
@@ -116,10 +115,10 @@ settingsRouter.activate(apiRouter);
116115
Services.log.info("Settings router activated");
117116
roleRouter.activate(apiRouter);
118117
Services.log.info("Role router activated");
118+
emailsRouter.activate(apiRouter);
119+
Services.log.info("Emails router activated");
119120

120-
apiRouter.use("/", indexRouter);
121121
app.use("/", indexRouter);
122-
123122
app.use("/api", apiRouter);
124123

125124
//Custom error handler
@@ -140,10 +139,10 @@ app.use((err, req, res, next) => {
140139
}
141140
res.status(status).json({
142141
message: message,
143-
data: errorContents
142+
data: errorContents,
144143
});
145144
});
146145

147146
module.exports = {
148-
app: app
147+
app: app,
149148
};

0 commit comments

Comments
 (0)