generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathapp.js
More file actions
24 lines (20 loc) · 826 Bytes
/
app.js
File metadata and controls
24 lines (20 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const express = require("express");
const extractUsername = require("./middleware/extractUsername");
const parseJsonArrayBody = require("./middleware/parseJsonArrayBody");
const app = express();
app.post("/subjects", extractUsername, parseJsonArrayBody, (req, res) => {
const auth = req.username
? `You are authenticated as ${req.username}.`
: "You are not authenticated.";
const subjectCount = req.body.length;
const subjectLabel = subjectCount === 1
? "subject"
: "subjects";
const subjectList = req.body.join(", ");
const subjectMessage =
subjectCount === 0
? "You have requested information about 0 subjects."
: `You have requested information about ${subjectCount} ${subjectLabel}: ${subjectList}.`;
res.send(`${auth} ${subjectMessage}`);
});
module.exports = app;