Skip to content

Instantly share code, notes, and snippets.

View designdevy's full-sized avatar
🧪
experimenting

Muhammad Athar designdevy

🧪
experimenting
View GitHub Profile
@designdevy
designdevy / nginx-websocket-proxy.conf
Created September 13, 2022 10:46 — forked from uorat/nginx-websocket-proxy.conf
Nginx Reverse Proxy for WebSocket
upstream websocket {
server localhost:3000;
}
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/websocket.access.log main;
function humanize(num){
var ones = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine',
'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen',
'seventeen', 'eighteen', 'nineteen'];
var tens = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty',
'ninety'];
var numString = num.toString();
if (num < 0) throw new Error('Negative numbers are not supported.');
// This is a sample of what the event object that gets
// passed to your connect route could look like.
// I've chosen to use an authorizer that will pass
// the userId so that I can store the connectionId with the userId
// in my database
interface APIGatewayWebsocketEvent {
methodArn: string;
queryStringParameters: {
token: string;
import * as _ from 'lodash';
import * as jwt from 'jsonwebtoken';
import * as jwkToPem from 'jwk-to-pem';
import * as moment from 'moment';
import * as request from 'request';
interface DecodedJWT {
aud: string;
iss: string;
exp: number;
import { Action } from 'redux';
interface User {
name: string;
age: number;
}
export interface LoadingState {
users: boolean;
}
import { User, LoadUsersRequest, LoadUsersSuccess, LoadUsersError } from './types';
export const loadUsersRequest = (): LoadUsersRequest => ({
type: 'loadUsersRequest',
});
export const loadUsersSuccess = (users: User[]): LoadUsersSuccess => ({
type: 'loadUsersSuccess',
users,
});
import { ThunkAction } from 'redux-thunk';
import { ApplicationState, ApplicationAction } from './types';
import { loadUsersRequest, loadUsersSuccess, loadUsersError } from './actions';
import * as userService from '../services/userService';
type Effect = ThunkAction<any, ApplicationState, any, ApplicationAction>;
export const loadUsers = (): Effect => (dispatch, getState) => {
dispatch(loadUsersRequest());
// assume userService.loadUsers returns a Promise<User[]>
import produce from 'immer';
import { ApplicationState, ApplicationAction } from './types';
export const initialState: ApplicationState = {
loading: {
users: false,
},
users: [],
}
const carsReducer = (state = carState, action) => {
switch (action.type) {
"loadUsersSuccess":
}
}
import React from 'react';
import ReactDOM from 'react-dom';
import { applyMiddleware, createStore } from 'redux';
import thunk from 'redux-thunk';
import { Provider } from 'react-redux';
import reducer, { initialState } from './store/reducer';
import App from './components/App';
// If you are interested in using the redux devtools
import { composeWithDevTools } from 'redux-devtools-extension';