Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix websocket paths and exclude websockets from client redirect #9593

Merged
merged 2 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions generators/client/files-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ const files = {
{ file: 'admin/tracker/tracker.route.ts', method: 'processJs' },
{ file: 'admin/tracker/tracker.component.ts', method: 'processJs' },
{ file: 'admin/tracker/tracker.component.html', method: 'processHtml' },
'core/tracker/tracker.service.ts',
'core/tracker/window.service.ts'
'core/tracker/tracker.service.ts'
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export * from './auth/auth-session.service';
<%_ } _%>
<%_ if (websocket === 'spring-websocket') { _%>
export * from './tracker/tracker.service';
export * from './tracker/window.service';
<%_ } _%>
<%_ if (enableTranslation) { _%>
export * from './language/language.helper';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import { Injectable } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { Observable, Observer, Subscription } from 'rxjs';
import { Location } from '@angular/common';

import { CSRFService } from '../auth/csrf.service';
import { WindowRef } from './window.service';
<%_ if (authenticationType === 'jwt' || authenticationType === 'uaa') { _%>
import { AuthServerProvider } from '../auth/auth-jwt.service';
<%_ } _%>
Expand All @@ -45,7 +45,7 @@ export class <%=jhiPrefixCapitalized%>TrackerService {
<%_ if (authenticationType === 'jwt' || authenticationType === 'uaa') { _%>
private authServerProvider: AuthServerProvider,
<%_ } _%>
private $window: WindowRef,
private location: Location,
// tslint:disable-next-line: no-unused-variable
private csrfService: CSRFService
) {
Expand All @@ -58,9 +58,8 @@ export class <%=jhiPrefixCapitalized%>TrackerService {
this.connection = this.createConnection();
}
// building absolute path so that websocket doesn't fail when deploying with a context path
const loc = this.$window.nativeWindow.location;
let url;
url = '//' + loc.host + loc.pathname + 'websocket/tracker';
let url = '/websocket/tracker';
url = this.location.prepareExternalUrl(url);
Copy link
Member Author

@ruddell ruddell Apr 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This builds a full URL including the base path specified in index.html (source)

<%_ if (authenticationType === 'jwt' || authenticationType === 'uaa') { _%>
const authToken = this.authServerProvider.getToken();
if (authToken) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
limitations under the License.
-%>
const webpack = require('webpack');
const { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const rxPaths = require('rxjs/_esm5/path-mapping');
Expand Down Expand Up @@ -111,6 +112,7 @@ module.exports = (options) => ({
chunks: ['vendors', 'polyfills', 'main', 'global'],
chunksSortMode: 'manual',
inject: 'body'
})
}),
new BaseHrefWebpackPlugin({ baseHref: '/' })
]
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
-%>
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const Visualizer = require('webpack-visualizer-plugin');
Expand Down Expand Up @@ -178,8 +177,7 @@ module.exports = webpackMerge(commonConfig({ env: ENV }), {
new WorkboxPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true,
}),
new BaseHrefWebpackPlugin({ baseHref: '/' })
})
],
mode: 'production'
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import ErrorBoundary from 'app/shared/error/error-boundary';
import { AUTHORITIES } from 'app/config/constants';
import AppRoutes from 'app/routes';

const baseHref = document.querySelector('base').getAttribute('href').replace(/\/$/, '');

export interface IAppProps extends StateProps, DispatchProps {}

export class App extends React.Component<IAppProps> {
Expand All @@ -50,7 +52,7 @@ export class App extends React.Component<IAppProps> {
render() {
const paddingTop = '60px';
return (
<Router>
<Router basename={baseHref}>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required when deploying under a context-path other than /, fixes all links to include the base href (docs)

<div className="app-container" style={{ paddingTop }}>
<ToastContainer position={toast.POSITION.TOP_LEFT} className="toastify-container" toastClassName="toastify-toast"/>
<ErrorBoundary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ const connect = () => {

// building absolute path so that websocket doesn't fail when deploying with a context path
const loc = window.location;
const baseHref = document.querySelector('base').getAttribute('href').replace(/\/$/, '');

const headers = {};
<%_ if (authenticationType === 'session') { _%>
const url = '//' + loc.host + loc.pathname + 'websocket/tracker';
const url = '//' + loc.host + baseHref + '/websocket/tracker';
headers['X-XSRF-TOKEN'] = cookie.read('XSRF-TOKEN');
<%_ } else { _%>
let url = '//' + loc.host + loc.pathname + 'websocket/tracker';
let url = '//' + loc.host + baseHref + '/websocket/tracker';
const authToken = Storage.local.get('jhi-authenticationToken') || Storage.session.get('jhi-authenticationToken');
if (authToken) {
url += '?access_token=' + authToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
limitations under the License.
-%>
const webpack = require('webpack');
const { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
Expand Down Expand Up @@ -148,6 +149,7 @@ module.exports = options => ({
chunksSortMode: 'dependency',
inject: 'body'
}),
new BaseHrefWebpackPlugin({ baseHref: '/' }),
<%_ if (enableTranslation) { _%>
new MergeJsonWebpackPlugin({
output: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
-%>
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
Expand Down Expand Up @@ -122,7 +121,6 @@ module.exports = webpackMerge(commonConfig({ env: ENV }), {
new WorkboxPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true,
}),
new BaseHrefWebpackPlugin({ baseHref: '/' })
})
]
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ClientForwardController {
* Forwards any unmapped paths (except those containing a period) to the client {@code index.html}.
* @return forward to client {@code index.html}.
*/
@GetMapping(value = "/**/{path:[^\\.]*}")
@GetMapping(value = "/**/{path:<% if (websocket === 'spring-websocket') { %>^(?!websocket)<% } %>[^\\.]*}")
public String forward() {
return "forward:/";
}
Expand Down