Skip to content

Commit 653f19f

Browse files
committed
Add next parameter support on login route and improve WebSocket base URL handling
1 parent bf4e603 commit 653f19f

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- added ability to refresh menu item badge from the backend using websocket publish
1717
- fix bugs when e.g. UR (urdu) can't be recognized by LLM (define names explicitly)
1818
- make user menu switch shorter
19+
- next param support on login route
1920

2021
# Improved
2122

2223
- Added separate BeforeCreateSave function in types without oldRecord and make oldRecord Mandatory in existing BeforeSaveFunction
2324

2425
- Added dataConnector: IAdminForthDataSourceConnectorBase; into IOperationalResource - for reusing connectors from users code
2526

27+
# Fixed
28+
29+
- WS on base URL
30+
31+
2632
## [v1.5.7] - 2024-12-09
2733

2834
### Fixed

adminforth/servers/express.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,13 @@ class ExpressServer implements IExpressHttpServer {
163163
}
164164

165165
setupWsServer() {
166+
let base = this.adminforth.config.baseUrl || '';
167+
if (base.endsWith('/')) {
168+
base = base.slice(0, -1);
169+
}
170+
166171
this.server = http.createServer(this.expressApp);
167-
const wss = new WebSocketServer({ server: this.server, path: '/afws' });
172+
const wss = new WebSocketServer({ server: this.server, path: `${base}/afws` });
168173
console.log(' 🌐WebSocket server started');
169174
// Handle WebSocket connections
170175
wss.on('connection', async (ws, req) => {

adminforth/spa/src/router/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ const router = createRouter({
1616
customLayout: true
1717
},
1818
beforeEnter: async (to, from, next) => {
19-
if(localStorage.getItem('isAuthorized') === 'true'){
20-
next({name: 'home'})
19+
if(localStorage.getItem('isAuthorized') === 'true') {
20+
// check if url has next=... and redirect to it
21+
console.log('to.query', to.query)
22+
if (to.query.next) {
23+
next(to.query.next.toString())
24+
} else {
25+
next({name: 'home'});
26+
}
2127
} else {
2228
next()
2329
}

adminforth/spa/src/websocket.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ async function connect () {
2727
console.error('🔌 AFWS already connected');
2828
return;
2929
}
30+
31+
let base = import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH || '';
32+
if (base.endsWith('/')) {
33+
base = base.slice(0, -1);
34+
}
35+
3036
state.ws = new WebSocket(`${
3137
window.location.protocol === 'http:' ? 'ws' : 'wss'
32-
}://${window.location.host}/afws`);
38+
}://${window.location.host}${base}/afws`);
3339
state.status = 'connecting';
3440
state.ws.addEventListener('open', () => {
3541
console.log('🔌 AFWS connected');

0 commit comments

Comments
 (0)