feat: unified portal server, single database migration & railway configuration
This commit is contained in:
BIN
Binary file not shown.
@@ -224,7 +224,7 @@
|
||||
// ----------------------------------------------------------------
|
||||
// MARKERS STORE { id: { marker, spbu, group } }
|
||||
// ----------------------------------------------------------------
|
||||
const API_URL = 'http://localhost:3000/api/spbus';
|
||||
const API_URL = '/api/spbus';
|
||||
let tempPopup = null;
|
||||
let markers = {};
|
||||
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
"name": "webgis_gasstation",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node server.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
||||
@@ -11,22 +11,38 @@ app.use(bodyParser.json());
|
||||
app.use(express.static(__dirname));
|
||||
|
||||
// Create MySQL connection
|
||||
const db = mysql.createConnection({
|
||||
host: process.env.DB_HOST || 'localhost',
|
||||
user: process.env.DB_USER || 'root',
|
||||
password: process.env.DB_PASSWORD || '',
|
||||
database: process.env.DB_NAME || 'spbu_gis',
|
||||
port: process.env.DB_PORT || 3306
|
||||
});
|
||||
let db;
|
||||
function handleDisconnect() {
|
||||
const connectionString = process.env.DATABASE_URL || process.env.MYSQL_URL || process.env.MYSQL_PRIVATE_URL;
|
||||
db = connectionString
|
||||
? mysql.createConnection(connectionString)
|
||||
: mysql.createConnection({
|
||||
host: process.env.DB_HOST || 'localhost',
|
||||
user: process.env.DB_USER || 'root',
|
||||
password: process.env.DB_PASSWORD || '',
|
||||
database: process.env.DB_NAME || 'spbu_gis',
|
||||
port: process.env.DB_PORT || 3306
|
||||
});
|
||||
|
||||
db.connect(err => {
|
||||
if (err) {
|
||||
console.error('Database connection failed: ' + err.stack);
|
||||
setTimeout(handleDisconnect, 2000);
|
||||
} else {
|
||||
console.log('Connected to MySQL database.');
|
||||
}
|
||||
});
|
||||
|
||||
db.connect(err => {
|
||||
if (err) {
|
||||
console.error('Database connection failed: ' + err.stack);
|
||||
return;
|
||||
}
|
||||
console.log('Connected to MySQL database.');
|
||||
});
|
||||
db.on('error', err => {
|
||||
console.error('Database error:', err);
|
||||
if (err.code === 'PROTOCOL_CONNECTION_LOST') {
|
||||
handleDisconnect();
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
}
|
||||
handleDisconnect();
|
||||
|
||||
// GET route to fetch all SPBU locations
|
||||
app.get('/api/spbus', (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user