Skip to content

Commit

Permalink
Add version check to server
Browse files Browse the repository at this point in the history
  • Loading branch information
lmg-anon committed May 22, 2024
1 parent 9f8d621 commit 2b7f0b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 11 additions & 3 deletions mikupad.html
Original file line number Diff line number Diff line change
Expand Up @@ -2915,9 +2915,17 @@
}

async init() {
// Test connection
const db = await this.openDatabase();
await this.loadFromDatabase(db, "Sessions", "selectedSessionId");
const res = await fetch(new URL('/version', this.sessionEndpoint), {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
if (!res.ok)
throw new Error("Not a mikupad server or version mismatch.");
const { version } = await res.json();
if (version !== 2)
throw new Error("Mikupad server version mismatch.");
}

async openDatabase() {
Expand Down
7 changes: 7 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'mikupad.html'));
});

// GET route to get the server version
app.get('/version', (req, res) => {
res.json({ version: 2 });
});

// Dynamic POST proxy route
app.post('/proxy/*', async (req, res) => {
// Capture the part of the URL after '/proxy'
Expand Down Expand Up @@ -148,6 +153,8 @@ app.get('/proxy/*', async (req, res) => {
});

const normalizeStoreName = (storeName) => {
if (!storeName)
return "Sessions";
return storeName.split(' ')[0].toLowerCase();
};

Expand Down

0 comments on commit 2b7f0b0

Please sign in to comment.