Skip to content

Commit

Permalink
Fixed bug with overwriting opened tabs. Added proxy for websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelmalak committed Jun 10, 2021
1 parent 936da30 commit 78de875
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 114 deletions.
4 changes: 2 additions & 2 deletions Socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class Socket {
this.webSocketServer = new WebSocket.Server({ server })

this.webSocketServer.on('listening', () => {
console.log('socket listen');
console.log('Socket: listen');
})

this.webSocketServer.on('connection', (webSocketClient) => {
console.log('new connection');
console.log('Socket: new connection');
})
}

Expand Down
130 changes: 30 additions & 100 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@types/react-redux": "^7.1.16",
"@types/react-router-dom": "^5.1.7",
"axios": "^0.21.1",
"http-proxy-middleware": "^2.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.4",
Expand Down Expand Up @@ -50,6 +51,5 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:5005"
}
}
2 changes: 1 addition & 1 deletion client/src/components/Apps/AppCard/AppCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const AppCard = (props: ComponentProps): JSX.Element => {
}

return (
<a href={`http://${props.app.url}`} target='blank' className={classes.AppCard}>
<a href={`http://${props.app.url}`} target='_blank' className={classes.AppCard}>
<div className={classes.AppCardIcon}>
<Icon icon={iconParser(props.app.icon)} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const BookmarkCard = (props: ComponentProps): JSX.Element => {
{props.category.bookmarks.map((bookmark: Bookmark) => (
<a
href={`http://${bookmark.url}`}
target='blank'
target='_blank'
key={`bookmark-${bookmark.id}`}>
{bookmark.icon && (
<div className={classes.BookmarkIcon}>
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/UI/Icons/WeatherIcon/WeatherIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ interface ComponentProps {

const WeatherIcon = (props: ComponentProps): JSX.Element => {
const icon = props.isDay
? (new IconMapping).mapIcon(props.weatherStatusCode, TimeOfDay.day)
: (new IconMapping).mapIcon(props.weatherStatusCode, TimeOfDay.night);
? new IconMapping().mapIcon(props.weatherStatusCode, TimeOfDay.day)
: new IconMapping().mapIcon(props.weatherStatusCode, TimeOfDay.night);

useEffect(() => {
const delay = setTimeout(() => {
Expand All @@ -25,7 +25,7 @@ const WeatherIcon = (props: ComponentProps): JSX.Element => {
return () => {
clearTimeout(delay);
}
}, [props.weatherStatusCode]);
}, [props.weatherStatusCode, icon, props.theme.colors.accent]);

return <canvas id={`weather-icon`} width='50' height='50'></canvas>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ const WeatherWidget = (): JSX.Element => {

// Open socket for data updates
useEffect(() => {
const webSocketClient = new WebSocket('ws://localhost:5005');
const webSocketClient = new WebSocket(`ws://${window.location.host}/socket`);

webSocketClient.onopen = () => {
console.log('Socket: listen')
}

webSocketClient.onmessage = (e) => {
const data = JSON.parse(e.data);
Expand Down
15 changes: 15 additions & 0 deletions client/src/setupProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function (app) {
const apiProxy = createProxyMiddleware('/api', {
target: 'http://localhost:5005'
})

const wsProxy = createProxyMiddleware('/socket', {
target: 'http://localhost:5005',
ws: true
})

app.use(apiProxy);
app.use(wsProxy);
};
5 changes: 1 addition & 4 deletions client/src/store/actions/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ export const getApps = () => async (dispatch: Dispatch) => {
payload: res.data.data
})
} catch (err) {
dispatch<GetAppsAction<string>>({
type: ActionTypes.getAppsError,
payload: err.data.data
})
console.log(err);
}
}

Expand Down

0 comments on commit 78de875

Please sign in to comment.