Skip to content

Commit

Permalink
Merge pull request #236 from connect-foundation/feature/https
Browse files Browse the repository at this point in the history
Feature/https
  • Loading branch information
beingPracticer authored Dec 20, 2019
2 parents 9ab1434 + fd30275 commit dc461c3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
6 changes: 3 additions & 3 deletions client/src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const MAX_DATE = '9999-12-31T09:29:26.050Z';

export const WRITING_FEED_CONTENT = 'writingFeedContent';

export const HTTP_SERVER_URI = `http://${config.serverHost}/graphql`;
export const HTTP_SERVER_URI = `${config.serverHost}/graphql`;

export const UPLOAD_SERVER_URI = `http://${config.serverHost}/graphql`;
export const UPLOAD_SERVER_URI = `${config.serverHost}/graphql`;

export const WEB_SOCKET_URI = `ws://${config.serverHost}/subscriptions`;
export const WEB_SOCKET_URI = `${config.webSocket}/subscriptions`;
2 changes: 1 addition & 1 deletion client/src/pages/SignIn/SignInBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Link = styled.a``;

const LoginBtn = () => {
return (
<Link href={`http://${config.serverHost}/auth/google`}>
<Link href={`${config.serverHost}/auth/google`}>
<LoginBtnImg
alt="LOGIN"
src={process.env.PUBLIC_URL + '/images/btn_google_signin_normal.png'}
Expand Down
6 changes: 4 additions & 2 deletions client/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ const configs = {
};

const devConfigs = {
serverHost: 'localhost:4000'
serverHost: 'http://localhost:4000',
webSocket: `ws://localhost:4000`
};

const prdConfigs = {
serverHost: process.env.REACT_APP_SERVER_HOST || ''
serverHost: `https://${process.env.REACT_APP_SERVER_HOST}`,
webSocket: `wss://${process.env.REACT_APP_SERVER_HOST}`
};

const config = Object.assign(
Expand Down
10 changes: 4 additions & 6 deletions server/src/init.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { Options } from 'graphql-yoga';
import config from './utils/config';
import app from './app';
import cors from './utils/cors';
import https from './utils/https';
import { onConnect, onDisconnect } from './middleware/subscription';

const PORT: string | number = config.port;
const ENDPOINT: string = '/graphql';
const PLAYGROUND: string = '/playground';
const SUBSCRIPTIONS: string = '/subscriptions';

const corsOptions = {
origin: config.clientHost,
credentials: true
};

const appOptions: Options = {
port: PORT,
endpoint: ENDPOINT,
Expand All @@ -23,7 +20,8 @@ const appOptions: Options = {
onDisconnect,
keepAlive: 10000
},
cors: corsOptions
cors,
https
};

const handleStart = () => {
Expand Down
8 changes: 8 additions & 0 deletions server/src/utils/cors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import config from './config';

const cors = {
origin: config.clientHost,
credentials: true
};

export default cors;
13 changes: 13 additions & 0 deletions server/src/utils/https.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import fs from 'fs';

const env = process.env.NODE_ENV || 'DEVELOPMENT';

const https =
env === 'PRODUCTION'
? {
cert: fs.readFileSync(process.env.CERT || ''),
key: fs.readFileSync(process.env.KEY || '')
}
: undefined;

export default https;

0 comments on commit dc461c3

Please sign in to comment.