You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Replace with your locally defined secrets for basic proxy auth
111
+
API_KEY="<API_KEY>"
113
112
API_SECRET="<API_SECRET>"
114
113
115
114
# Project variables
@@ -118,7 +117,7 @@ following code:
118
117
RATE_LIMIT_MAX=100 # Maximum requests per window
119
118
RATE_LIMIT_MESSAGE=Too many requests, please try again later.
120
119
121
-
Replace the following placeholders with your credentials:
120
+
Replace the following placeholders with your credentials:
122
121
123
122
- ``MONGO_URI`` Replace with the connection string for your deployment. For more information, see `Connection String Formats <https://www.mongodb.com/docs/manual/reference/connection-string/#connection-string-formats>`__.
124
123
@@ -127,8 +126,8 @@ Replace the following placeholders with your credentials:
- ``MONGO_OPTIONS`` Replace with the optional query string specifying any connection-specific options. For more information, see `Connection String Options <https://www.mongodb.com/docs/manual/reference/connection-string-options/>`__.
130
-
- ``API_KEY`` Replace with a valid API key.
131
-
- ``API_SECRET`` Replace with the corresponding API secret.
129
+
- ``API_KEY`` Replace with a locally defined key used to authenticate requests to your proxy server. This is not an Atlas API key.
130
+
- ``API_SECRET`` Replace with the corresponding locally defined secret.
132
131
133
132
Initialize the Server
134
133
~~~~~~~~~~~~~~~~~~~~~
@@ -148,17 +147,18 @@ The server includes middleware for the following:
148
147
:caption: index.js
149
148
150
149
/**
151
-
* This file initializes the server, validates API keys for added security,
152
-
* and routes requests to the appropriate controller methods.
150
+
* This file initializes the Express server, validates locally defined API keys,
151
+
* applies basic rate limiting, and routes incoming requests to API controller methods.
153
152
*/
154
153
const rateLimit = require("express-rate-limit");
155
154
const express = require("express");
156
155
const apiRoutes = require("./routes/api");
157
156
const logger = require("./utils/logging");
158
157
require("dotenv").config();
159
158
160
-
const API_KEY = process.env.API_KEY; // Load API key from .env
161
-
const API_SECRET = process.env.API_SECRET; // Load API secret from .env
159
+
// Load local shared secrets from environment variables
160
+
const API_KEY = process.env.API_KEY;
161
+
const API_SECRET = process.env.API_SECRET;
162
162
163
163
const app = express();
164
164
@@ -174,7 +174,8 @@ The server includes middleware for the following:
174
174
// Middleware for parsing requests
175
175
app.use(express.json());
176
176
177
-
// Middleware for API key authentication and logging
177
+
// Middleware for basic API key authentication
178
+
// NOTE: Replace this with your preferred authentication method in production
178
179
app.use((req, res, next) => {
179
180
logger.info({
180
181
method: req.method,
@@ -185,7 +186,7 @@ The server includes middleware for the following:
185
186
const apiKey = req.headers["x-api-key"];
186
187
const apiSecret = req.headers["x-api-secret"];
187
188
if (apiKey === API_KEY && apiSecret === API_SECRET) {
188
-
next(); // Proceed to the next middleware or route
189
+
next(); // Authorized
189
190
} else {
190
191
res.status(403).json({ message: "Forbidden: Invalid API Key or Secret" });
191
192
}
@@ -237,7 +238,7 @@ The ``databaseManager.js`` file handles the MongoDB database connections using
237
238
the ``mongoose`` library. Connection details are stored in the ``.env`` file.
0 commit comments