Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -2,8 +2,10 @@ const express = require('express');
|
|
| 2 |
const fs = require('fs');
|
| 3 |
const path = require('path');
|
| 4 |
const crypto = require('crypto');
|
|
|
|
| 5 |
|
| 6 |
const app = express();
|
|
|
|
| 7 |
|
| 8 |
// Function to validate an IP address
|
| 9 |
const validateIp = (ip) => {
|
|
@@ -37,6 +39,9 @@ app.get('/checkState', (req, res) => {
|
|
| 37 |
};
|
| 38 |
fs.writeFileSync(infoPath, JSON.stringify(infoData, null, 2));
|
| 39 |
|
|
|
|
|
|
|
|
|
|
| 40 |
// Send API key to frontend
|
| 41 |
res.status(200).json({ message: 'Server is running successfully', apiKey: apiKey });
|
| 42 |
} else {
|
|
|
|
| 2 |
const fs = require('fs');
|
| 3 |
const path = require('path');
|
| 4 |
const crypto = require('crypto');
|
| 5 |
+
const cookieParser = require('cookie-parser');
|
| 6 |
|
| 7 |
const app = express();
|
| 8 |
+
app.use(cookieParser());
|
| 9 |
|
| 10 |
// Function to validate an IP address
|
| 11 |
const validateIp = (ip) => {
|
|
|
|
| 39 |
};
|
| 40 |
fs.writeFileSync(infoPath, JSON.stringify(infoData, null, 2));
|
| 41 |
|
| 42 |
+
// Set the API key in a cookie with a 1-hour lifetime
|
| 43 |
+
res.cookie('apiKey', apiKey, { maxAge: 3600000, httpOnly: true });
|
| 44 |
+
|
| 45 |
// Send API key to frontend
|
| 46 |
res.status(200).json({ message: 'Server is running successfully', apiKey: apiKey });
|
| 47 |
} else {
|