Skip to content

Commit

Permalink
Merge pull request #51 from T4rk1n/50-fix-ws-urls
Browse files Browse the repository at this point in the history
Fix page ws url
  • Loading branch information
T4rk1n committed Jan 13, 2020
2 parents dc90f37 + 730552f commit 1ec9ab6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/python:3.7-stretch-node-browsers
- image: circleci/python:3.8-buster-node-browsers
- image: circleci/redis:latest
environment:
PYTHONPATH: ~/repo
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Versions follow [Semantic Versioning](https://www.semver.org)

- :bug: Fix page requirements url. [#35](https://github.com/T4rk1n/dazzler/issues/35)
- :bug: Fix aspect docstrings. [#34](https://github.com/T4rk1n/dazzler/issues/34)
- :bug: Fix page url with `/`. [#50](https://github.com/T4rk1n/dazzler/issues/50)

## [0.2.0]
### Added
Expand Down
2 changes: 1 addition & 1 deletion dazzler/_dazzler.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ async def setup_server(self, debug=False):
method=RouteMethod.POST,
),
Route(
f'{page.url}/ws',
f'/{page.name}/ws',
functools.partial(self.server.route_update, page=page),
name=f'{page.name}-ws',
method=RouteMethod.GET,
Expand Down
1 change: 1 addition & 0 deletions dazzler/system/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def __init__(self, app, backend=None):
salt=app.config.session.salt
)
self._backend = backend or FileSessionBackEnd(app)
# pylint: disable=E1121
self._sessions_queues = weakref.WeakValueDictionary()
self._query_queue = asyncio.Queue()
loop = asyncio.get_event_loop()
Expand Down
51 changes: 27 additions & 24 deletions src/renderer/js/components/Updater.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,11 @@ export default class Updater extends React.Component {
let tries = 0;
let hardClose = false;
const connexion = () => {
this.ws = new WebSocket(
`ws${
window.location.href.startsWith('https') ? 's' : ''
}://${(this.props.baseUrl && this.props.baseUrl) ||
window.location.host}${window.location.pathname}/ws`
);
const url = `ws${
window.location.href.startsWith('https') ? 's' : ''
}://${(this.props.baseUrl && this.props.baseUrl) ||
window.location.host}/${this.state.page}/ws`;
this.ws = new WebSocket(url);
this.ws.addEventListener('message', this.onMessage);
this.ws.onopen = () => {
if (this.state.reloading) {
Expand Down Expand Up @@ -232,24 +231,28 @@ export default class Updater extends React.Component {

componentWillMount() {
this.pageApi('', {method: 'POST'}).then(response => {
this.setState({
page: response.page,
layout: response.layout,
bindings: response.bindings,
packages: response.packages,
requirements: response.requirements,
});
loadRequirements(response.requirements, response.packages).then(
() => {
if (
Object.keys(response.bindings).length ||
response.reload
) {
this._connectWS();
} else {
this.setState({ready: true});
}
}
this.setState(
{
page: response.page,
layout: response.layout,
bindings: response.bindings,
packages: response.packages,
requirements: response.requirements,
},
() =>
loadRequirements(
response.requirements,
response.packages
).then(() => {
if (
Object.keys(response.bindings).length ||
response.reload
) {
this._connectWS();
} else {
this.setState({ready: true});
}
})
);
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dazzler_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def get_user(self, username: str) -> User:
@pytest.fixture
def auth_app():
app = Dazzler(__name__)
page = Page(__name__, core.Container([
page = Page('test-auth', core.Container([
core.Html('h2', 'logged-in', identity='header'),
core.Container(identity='username-output'),
_auth.Logout('/auth/logout', identity='logout')
Expand Down Expand Up @@ -97,7 +97,7 @@ async def test_unauthenticated_ws(auth_app):
async with client.ClientSession() as session:
with pytest.raises(aiohttp.WSServerHandshakeError) as context:
async with session.ws_connect(
'ws://localhost:8150//ws') as ws:
'ws://localhost:8150/test-auth/ws') as ws:
await ws.close()

assert context.value.status == 401
Expand Down

0 comments on commit 1ec9ab6

Please sign in to comment.