-
-
Notifications
You must be signed in to change notification settings - Fork 76
WM5 | KARAM ALI | MODULE SERVERS | MAILING LIST API | WEEK 4 #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ module.exports = { | |
| "khadar@techtonica.org", | ||
| ], | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import express from "express"; | ||
| const app = express(); | ||
| app.use(express.json()); | ||
|
|
||
| const lists = new Map(); | ||
| lists.set("staff", ["talea@techtonica.org", "michelle@techtonica.org"]); | ||
| lists.set("cohort-h1-2020", [ | ||
| "ali@techtonica.org", | ||
| "humail@techtonica.org", | ||
| "khadar@techtonica.org", | ||
| ]); | ||
|
|
||
| app.get("/lists", (req, res) => { | ||
| const listsArray = Array.from(lists.keys()); | ||
| lists | ||
| ? res.status(200).send({ lists: listsArray }) | ||
| : res.status(200).send({}); | ||
| }); | ||
|
|
||
| app.get("/lists/:name", (req, res) => { | ||
| const params = req.params.name; | ||
|
|
||
| lists.has(params) | ||
| ? res.status(200).send({ name: params, members: lists.get(params) }) | ||
| : res.status(404); | ||
| }); | ||
|
|
||
| app.delete("/lists/:name", (req, res) => { | ||
| const params = req.params.name; | ||
| lists.delete(params) | ||
| ? res.status(200).send(`Deleted ${params} successfully!`) | ||
| : res.status(404); | ||
| }); | ||
|
|
||
| app.put("/lists/:name", (req, res) => { | ||
| const params = req.params.name; | ||
| const body = req.body; | ||
|
|
||
| if (params.toLowerCase() !== body.name.toLowerCase()) { | ||
| res | ||
| .status(400) | ||
| .send( | ||
Check failureCode scanning / SonarCloud Endpoints should not be vulnerable to reflected cross-site scripting (XSS) attacks
<!--SONAR_ISSUE_KEY:AY93W648zMRAKKOjksrt-->Change this code to not reflect user-controlled data. <p>See more on <a href="https://sonarcloud.io/project/issues?id=CodeYourFuture_Module-Node&issues=AY93W648zMRAKKOjksrt&open=AY93W648zMRAKKOjksrt&pullRequest=186">SonarCloud</a></p>
|
||
| `Request could not be completed. Path (${params}) & JSON body ("name": ${body.name}) do not match` | ||
| ); | ||
| } | ||
|
|
||
| if (lists.has(params)) { | ||
| lists.set(params, body.members); | ||
| res.send(`List ${params} has been updated`); | ||
Check failureCode scanning / SonarCloud Endpoints should not be vulnerable to reflected cross-site scripting (XSS) attacks
<!--SONAR_ISSUE_KEY:AY93W648zMRAKKOjksrs-->Change this code to not reflect user-controlled data. <p>See more on <a href="https://sonarcloud.io/project/issues?id=CodeYourFuture_Module-Node&issues=AY93W648zMRAKKOjksrs&open=AY93W648zMRAKKOjksrs&pullRequest=186">SonarCloud</a></p>
|
||
| } else { | ||
| lists.set(params, body.members); | ||
| res.send(`New list ${params} has been created`); | ||
Check failureCode scanning / SonarCloud Endpoints should not be vulnerable to reflected cross-site scripting (XSS) attacks
<!--SONAR_ISSUE_KEY:AY93W648zMRAKKOjksru-->Change this code to not reflect user-controlled data. <p>See more on <a href="https://sonarcloud.io/project/issues?id=CodeYourFuture_Module-Node&issues=AY93W648zMRAKKOjksru&open=AY93W648zMRAKKOjksru&pullRequest=186">SonarCloud</a></p>
|
||
| } | ||
| }); | ||
|
|
||
| const listener = app.listen(3003, () => { | ||
| console.log(`Your listening on port ${listener.address().port}`); | ||
| }); | ||
Check failure
Code scanning / SonarCloud
Endpoints should not be vulnerable to reflected cross-site scripting (XSS) attacks