Update server.js
Browse files
server.js
CHANGED
|
@@ -5,6 +5,7 @@ import { v4 as uuidv4 } from 'uuid';
|
|
| 5 |
import fileUpload from 'express-fileupload';
|
| 6 |
import path from 'path';
|
| 7 |
import { fileURLToPath } from 'url';
|
|
|
|
| 8 |
|
| 9 |
const __filename = fileURLToPath(import.meta.url);
|
| 10 |
const __dirname = path.dirname(__filename);
|
|
@@ -17,7 +18,10 @@ if (!ADMIN_PASSWORD) {
|
|
| 17 |
process.exit(1);
|
| 18 |
}
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
const KEY_DEACTIVATION_THRESHOLD = 5;
|
| 22 |
const KEY_COOLDOWN_SECONDS = 60;
|
| 23 |
|
|
@@ -26,6 +30,11 @@ app.use(express.json({ limit: '10mb' }));
|
|
| 26 |
app.use(express.urlencoded({ extended: true }));
|
| 27 |
app.use(fileUpload());
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
const sequelize = new Sequelize({
|
| 30 |
dialect: 'sqlite',
|
| 31 |
storage: DB_PATH,
|
|
@@ -561,4 +570,5 @@ sequelize.sync({ force: false }).then(() => {
|
|
| 561 |
}).catch(error => {
|
| 562 |
console.error('Failed to initialize database:', error);
|
| 563 |
process.exit(1);
|
| 564 |
-
});
|
|
|
|
|
|
| 5 |
import fileUpload from 'express-fileupload';
|
| 6 |
import path from 'path';
|
| 7 |
import { fileURLToPath } from 'url';
|
| 8 |
+
import fs from 'fs'; // Import the fs module
|
| 9 |
|
| 10 |
const __filename = fileURLToPath(import.meta.url);
|
| 11 |
const __dirname = path.dirname(__filename);
|
|
|
|
| 18 |
process.exit(1);
|
| 19 |
}
|
| 20 |
|
| 21 |
+
// Define the directory for the database
|
| 22 |
+
const DB_DIR = path.join(__dirname, 'data');
|
| 23 |
+
// Define the full path to the database file
|
| 24 |
+
const DB_PATH = path.join(DB_DIR, 'database.sqlite');
|
| 25 |
const KEY_DEACTIVATION_THRESHOLD = 5;
|
| 26 |
const KEY_COOLDOWN_SECONDS = 60;
|
| 27 |
|
|
|
|
| 30 |
app.use(express.urlencoded({ extended: true }));
|
| 31 |
app.use(fileUpload());
|
| 32 |
|
| 33 |
+
// Ensure the database directory exists before initializing Sequelize
|
| 34 |
+
if (!fs.existsSync(DB_DIR)) {
|
| 35 |
+
fs.mkdirSync(DB_DIR, { recursive: true });
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
const sequelize = new Sequelize({
|
| 39 |
dialect: 'sqlite',
|
| 40 |
storage: DB_PATH,
|
|
|
|
| 570 |
}).catch(error => {
|
| 571 |
console.error('Failed to initialize database:', error);
|
| 572 |
process.exit(1);
|
| 573 |
+
});
|
| 574 |
+
|