Spaces:
Paused
Paused
Update app.js
Browse files
app.js
CHANGED
|
@@ -7,6 +7,14 @@ const agent = new ProxyAgent();
|
|
| 7 |
const app = express();
|
| 8 |
const port = process.env.PORT || 8081;
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
var opts = {
|
| 11 |
agent: agent,
|
| 12 |
auth: {
|
|
@@ -27,19 +35,12 @@ var opts = {
|
|
| 27 |
},
|
| 28 |
};
|
| 29 |
|
| 30 |
-
function getAuthKey(req) {
|
| 31 |
-
const authHeader = req.headers['authorization'];
|
| 32 |
-
if (authHeader && authHeader.startsWith('Bearer ')) {
|
| 33 |
-
return authHeader.slice(7);
|
| 34 |
-
}
|
| 35 |
-
return null;
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
app.post("/api/v1/messages", (req, res) => {
|
| 39 |
const authKey = getAuthKey(req);
|
| 40 |
if (authKey !== process.env.AUTH_KEY) {
|
| 41 |
return res.status(401).json({ error: 'Unauthorized' });
|
| 42 |
-
}
|
|
|
|
| 43 |
req.rawBody = "";
|
| 44 |
req.setEncoding("utf8");
|
| 45 |
|
|
|
|
| 7 |
const app = express();
|
| 8 |
const port = process.env.PORT || 8081;
|
| 9 |
|
| 10 |
+
function getAuthKey(req) {
|
| 11 |
+
const authHeader = req.headers['authorization'];
|
| 12 |
+
if (authHeader && authHeader.startsWith('Bearer ')) {
|
| 13 |
+
return authHeader.slice(7);
|
| 14 |
+
}
|
| 15 |
+
return null;
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
var opts = {
|
| 19 |
agent: agent,
|
| 20 |
auth: {
|
|
|
|
| 35 |
},
|
| 36 |
};
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
app.post("/api/v1/messages", (req, res) => {
|
| 39 |
const authKey = getAuthKey(req);
|
| 40 |
if (authKey !== process.env.AUTH_KEY) {
|
| 41 |
return res.status(401).json({ error: 'Unauthorized' });
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
req.rawBody = "";
|
| 45 |
req.setEncoding("utf8");
|
| 46 |
|