diff --git a/week-1/problems/0-horizontal-align/index.html b/week-1/problems/0-horizontal-align/index.html index 7b2f62cf..dd3b7228 100644 --- a/week-1/problems/0-horizontal-align/index.html +++ b/week-1/problems/0-horizontal-align/index.html @@ -8,14 +8,20 @@
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +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 | 1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +7x +1x +1x +1x +13x +1x +1x +1x + +1x +1x +1x | // You have to create a middleware for rate limiting a users request based on their username passed in the header
+
+const express = require('express');
+const app = express();
+
+// Your task is to create a global middleware (app.use) which will
+// rate limit the requests from a user to only 5 request per second
+// If a user sends more than 5 requests in a single second, the server
+// should block them with a 404.
+// User will be sending in their user id in the header as 'user-id'
+// You have been given a numberOfRequestsForUser object to start off with which
+// clears every one second
+
+let numberOfRequestsForUser = {};
+setInterval(() => {
+ numberOfRequestsForUser = {};
+}, 1000)
+
+app.get('/user', function(req, res) {
+ res.status(200).json({ name: 'john' });
+});
+
+app.post('/user', function(req, res) {
+ res.status(200).json({ msg: 'created dummy user' });
+});
+
+module.exports = app; |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +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 | 1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +12x +12x +12x +12x +1x +1x +10x +1x +1x +1x + +1x +1x +1x +2x +1x +1x +1x | // You have to create a middleware for logging the number of requests on a server
+
+const express = require('express');
+
+const app = express();
+let requestCount = 0;
+
+app.use(countRequest);
+
+// You have been given an express server which has a few endpoints.
+// Your task is to create a global middleware (app.use) which will
+// maintain a count of the number of requests made to the server in the global
+// requestCount variable
+
+function countRequest(req, res, next){
+ requestCount++;
+ next();
+}
+
+app.get('/user', function(req, res) {
+ res.status(200).json({ name: 'john' });
+});
+
+app.post('/user', function(req, res) {
+ res.status(200).json({ msg: 'created dummy user' });
+});
+
+app.get('/requestCount', function(req, res) {
+ res.status(200).json({ requestCount });
+});
+
+module.exports = app; |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 | 1x +1x +1x +1x +1x +1x +1x +1x +1x +3x +3x +1x +1x +1x +1x +1x + +1x +1x +1x + + + |
+// Implement an authentication middleware that checks for a valid API key in the request headers.
+
+const express = require('express');
+const app = express();
+const VALID_API_KEY = '100xdevs_cohort3_super_secret_valid_api_key'; // key is 100xdevs-api-key use that API key for authenticate user
+
+
+// Middleware to check for a valid API key
+function authenticateAPIKey(req, res, next) {
+ // authenticate APIKey here
+}
+
+app.use(authenticateAPIKey);
+
+app.get('/', (req, res) => {
+ res.status(200).json({ message: 'Access granted' });
+});
+
+module.exports = app;
+
+
+ |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 | 1x +1x +1x +1x +1x +2x +2x +1x +1x +1x +1x +1x + +1x +1x +1x + | // Create a middleware that logs all incoming requests to the console.
+
+const express = require('express');
+const app = express();
+
+function logRequests(req, res, next) {
+ // write the logic for request log here
+}
+
+app.use(logRequests);
+
+app.get('/', (req, res) => {
+ res.status(200).json({ message: 'Hello, world!' });
+});
+
+module.exports = app;
+ |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
---|---|---|---|---|---|---|---|---|---|
01-ratelimitter.js | +
+
+ |
+ 96.29% | +26/27 | +100% | +2/2 | +100% | +0/0 | +96.29% | +26/27 | +
01-requestcount.js | +
+
+ |
+ 96.87% | +31/32 | +100% | +3/3 | +100% | +1/1 | +96.87% | +31/32 | +
02-authmiddleware.js | +
+
+ |
+ 95% | +19/20 | +100% | +1/1 | +100% | +1/1 | +95% | +19/20 | +
02-logIncomingRequests.js | +
+
+ |
+ 93.75% | +15/16 | +100% | +1/1 | +100% | +1/1 | +93.75% | +15/16 | +