Skip to content

Commit

Permalink
two new env variables: PRODUCTION_URL_APP, PRODUCTION_URL_API
Browse files Browse the repository at this point in the history
  • Loading branch information
tima101 committed Jun 19, 2018
1 parent 2eb3908 commit c524462
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 40 deletions.
3 changes: 2 additions & 1 deletion api/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ require('dotenv').config();

const dev = process.env.NODE_ENV !== 'production';
const port = process.env.PORT || 8000;
const ROOT_URL = dev ? `http://localhost:${port}` : 'https://saas-api.async-await.com';
const { PRODUCTION_URL_API } = process.env;
const ROOT_URL = dev ? `http://localhost:${port}` : PRODUCTION_URL_API;

let MONGO_URL = dev ? process.env.MONGO_URL_TEST : process.env.MONGO_URL;

Expand Down
12 changes: 5 additions & 7 deletions api/server/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import User, { IUserDocument } from './models/User';
import Invitation from './models/Invitation';

const dev = process.env.NODE_ENV !== 'production';
const { PRODUCTION_URL_APP } = process.env;
const URL_APP = dev ? 'http://localhost:3000' : PRODUCTION_URL_APP;

export default function auth({ ROOT_URL, server }) {
const clientID = process.env.Google_clientID;
Expand Down Expand Up @@ -90,7 +92,7 @@ export default function auth({ ROOT_URL, server }) {
}

if (req.user && req.user.isAdmin) {
res.redirect(dev ? 'http://localhost:3000/admin' : 'https://saas-app.async-await.com/admin');
res.redirect(`${URL_APP}/admin`);
} else {
let redirectUrlAfterLogin;

Expand All @@ -100,17 +102,13 @@ export default function auth({ ROOT_URL, server }) {
redirectUrlAfterLogin = `team/${req.user.defaultTeamSlug}/t/projects`;
}

res.redirect(
dev
? `http://localhost:3000/${redirectUrlAfterLogin}`
: `https://saas-app.async-await.com/${redirectUrlAfterLogin}`,
);
res.redirect(`${URL_APP}/${redirectUrlAfterLogin}`);
}
},
);

server.get('/logout', (req, res) => {
req.logout();
res.redirect(dev ? 'http://localhost:3000/login' : 'https://saas-app.async-await.com/login');
res.redirect(`${URL_APP}/login`);
});
}
3 changes: 2 additions & 1 deletion api/server/models/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import logger from '../logs';
import sendEmail from '../aws-ses';

const dev = process.env.NODE_ENV !== 'production';
const ROOT_URL = dev ? `http://localhost:3000` : 'https://saas-app.async-await.com';
const { PRODUCTION_URL_API } = process.env;
const ROOT_URL = dev ? `http://localhost:3000` : PRODUCTION_URL_API;

const mongoSchema = new mongoose.Schema({
teamId: {
Expand Down
8 changes: 5 additions & 3 deletions app/components/common/MenuWithMenuItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class MenuWithMenuItems extends React.PureComponent<{

return (
<span>
<Tooltip
{/* <Tooltip
title={menuOptions.tooltipTitle}
placement="top"
disableFocusListener
disableTouchListener
>
> */}
<a href="#" style={{ float: 'right' }} onClick={this.handleClick}>
<i
// aria-owns={menuOptions.ariaOwns}
Expand All @@ -43,7 +43,9 @@ class MenuWithMenuItems extends React.PureComponent<{
more_vert
</i>
</a>
</Tooltip>
{/* </Tooltip> */}

{/* Bug of MUI: https://github.com/mui-org/material-ui/issues/11913 */}

<Menu
id={menuOptions.id}
Expand Down
14 changes: 9 additions & 5 deletions app/components/discussions/DiscussionActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { Discussion, Store } from '../../lib/store';

import MenuWithMenuItems from '../common/MenuWithMenuItems';
import EditDiscussionForm from './EditDiscussionForm';
import env from '../../lib/env';

const dev = process.env.NODE_ENV !== 'production';
const ROOT_URL = dev ? `http://localhost:3000` : 'https://saas-app.async-await.com';
const { PRODUCTION_URL_APP } = env;
const ROOT_URL = dev ? `http://localhost:3000` : PRODUCTION_URL_APP;

const getMenuOptions = discussion => ({
dataId: discussion._id,
Expand Down Expand Up @@ -71,13 +73,15 @@ class DiscussionActionMenu extends React.Component<{ discussion: Discussion; sto
}
} catch (err) {
notify(err);
} finally {
this.setState({ discussionFormOpen: false, selectedDiscussion: null });
}
};

editDiscussion = event => {
const { currentTeam } = this.props.store;
if (!currentTeam) {
notify('You have not selected Team');
notify('You have not selected Team.');
return;
}

Expand All @@ -100,13 +104,13 @@ class DiscussionActionMenu extends React.Component<{ discussion: Discussion; sto
deleteDiscussion = async event => {
const { currentTeam } = this.props.store;
if (!currentTeam) {
notify('Team have not selected');
notify('You have not selected Team.');
return;
}

const { currentTopic } = currentTeam;
if (!currentTopic) {
notify('Topic have not selected');
notify('You have not selected Topic.');
return;
}

Expand All @@ -125,7 +129,7 @@ class DiscussionActionMenu extends React.Component<{ discussion: Discussion; sto
try {
await currentTopic.deleteDiscussion(id);

notify('You successfully deleted Discussion');
notify('You successfully deleted Discussion.');
NProgress.done();
} catch (error) {
console.error(error);
Expand Down
7 changes: 5 additions & 2 deletions app/lib/api/getRootUrl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import env from '../env';

export default function getRootUrl() {
const port = process.env.PORT || 8000;
const dev = process.env.NODE_ENV !== 'production';
const ROOT_URL = dev ? `http://localhost:${port}` : 'https://saas-api.async-await.com';

const { PRODUCTION_URL_API } = env;
const ROOT_URL = dev ? `http://localhost:${port}` : PRODUCTION_URL_API;

return ROOT_URL;
}
4 changes: 3 additions & 1 deletion app/now.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"env": {
"NODE_ENV": "production",
"GA_TRACKING_ID": "UA-114984707-3"
"GA_TRACKING_ID": "UA-114984707-3",
"PRODUCTION_URL_APP": "https://saas-app.async-await.com",
"PRODUCTION_URL_API": "https://saas-api.async-await.com"
},
"alias": "saas-app.async-await.com",
"scale": {
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"coverageDirectory": "./.coverage"
},
"dependencies": {
"@material-ui/core": "^1.2.1",
"@material-ui/core": "^1.2.2",
"@types/node": "^10.3.3",
"@zeit/next-typescript": "^0.1.1",
"downshift": "^1.31.16",
Expand Down
5 changes: 2 additions & 3 deletions app/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import htmlescape from 'htmlescape';

import getContext from '../lib/context';

const { GA_TRACKING_ID, StripePublishableKey } = process.env;
const env = { GA_TRACKING_ID, StripePublishableKey };
// console.log(GA_TRACKING_ID);
const { GA_TRACKING_ID, PRODUCTION_URL_APP, PRODUCTION_URL_API, StripePublishableKey } = process.env;
const env = { GA_TRACKING_ID, PRODUCTION_URL_APP, PRODUCTION_URL_API, StripePublishableKey };

class MyDocument extends Document {
render() {
Expand Down
5 changes: 3 additions & 2 deletions app/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import * as helmet from 'helmet';
import * as mobxReact from 'mobx-react';

import { getUser } from '../lib/api/public';

import routesWithSlug from './routesWithSlug';
import env from '../lib/env';

mobxReact.useStaticRendering(true);

const dev = process.env.NODE_ENV !== 'production';
const port = process.env.PORT || 3000;
const ROOT_URL = dev ? `http://localhost:${port}` : 'https://saas-app.async-await.com';
const { PRODUCTION_URL_APP } = env;
const ROOT_URL = dev ? `http://localhost:${port}` : PRODUCTION_URL_APP;

const app = next({ dev });
const handle = app.getRequestHandler();
Expand Down
63 changes: 49 additions & 14 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,9 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"

"@material-ui/core@^1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@material-ui/core/-/core-1.2.1.tgz#f8c73da10b875762b37be7167ec2ac79b027499f"
"@material-ui/core@^1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@material-ui/core/-/core-1.2.2.tgz#b074bdaa679d68af235b4d3f108f828ddcf6c1bc"
dependencies:
"@babel/runtime" "^7.0.0-beta.42"
"@types/jss" "^9.5.3"
Expand All @@ -707,9 +707,9 @@
prop-types "^15.6.0"
react-event-listener "^0.6.0"
react-jss "^8.1.0"
react-popper "^0.10.0"
react-popper "^1.0.0"
react-transition-group "^2.2.1"
recompose "^0.26.0 || ^0.27.0"
recompose "^0.27.0"
scroll "^2.0.3"
warning "^4.0.1"

Expand Down Expand Up @@ -1275,7 +1275,7 @@ babel-register@^6.26.0:
mkdirp "^0.5.1"
source-map-support "^0.4.15"

babel-runtime@^6.22.0, babel-runtime@^6.26.0:
babel-runtime@6.x.x, babel-runtime@^6.22.0, babel-runtime@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
dependencies:
Expand Down Expand Up @@ -1916,6 +1916,13 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

create-react-context@^0.2.1:
version "0.2.2"
resolved "https://registry.yarnpkg.com/create-react-context/-/create-react-context-0.2.2.tgz#9836542f9aaa22868cd7d4a6f82667df38019dca"
dependencies:
fbjs "^0.8.0"
gud "^1.0.0"

[email protected], cross-spawn@^5.0.1, cross-spawn@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
Expand Down Expand Up @@ -1960,7 +1967,11 @@ [email protected], "cssom@>= 0.3.2 < 0.4.0":
dependencies:
cssom "0.3.x"

csstype@^2.0.0, csstype@^2.2.0, csstype@^2.5.2:
csstype@^2.0.0, csstype@^2.5.2:
version "2.5.5"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.5.5.tgz#4125484a3d42189a863943f23b9e4b80fedfa106"

csstype@^2.2.0:
version "2.5.3"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.5.3.tgz#2504152e6e1cc59b32098b7f5d6a63f16294c1f7"

Expand Down Expand Up @@ -2753,7 +2764,7 @@ fb-watchman@^2.0.0:
dependencies:
bser "^2.0.0"

fbjs@^0.8.1, fbjs@^0.8.16:
fbjs@^0.8.0, fbjs@^0.8.1, fbjs@^0.8.16:
version "0.8.17"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.17.tgz#c4d598ead6949112653d6588b01a5cdcd9f90fdd"
dependencies:
Expand Down Expand Up @@ -3090,6 +3101,10 @@ growly@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"

gud@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/gud/-/gud-1.0.0.tgz#a489581b17e6a70beca9abe3ae57de7a499852c0"

handlebars@^4.0.3:
version "4.0.11"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.11.tgz#630a35dfe0294bc281edae6ffc5d329fc7982dcc"
Expand Down Expand Up @@ -3231,7 +3246,11 @@ [email protected]:
version "2.5.0"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.0.tgz#d2ca2dfc19c5a91c5a6615ce8e564ef0347e2a40"

hoist-non-react-statics@^2.3.1, hoist-non-react-statics@^2.5.0:
hoist-non-react-statics@^2.3.1:
version "2.5.5"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz#c5903cf409c0dfd908f388e619d86b9c1174cb47"

hoist-non-react-statics@^2.5.0:
version "2.5.4"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.4.tgz#fc3b1ac05d2ae3abedec84eba846511b0d4fcc4f"

Expand Down Expand Up @@ -4221,7 +4240,15 @@ jss-vendor-prefixer@^7.0.0:
dependencies:
css-vendor "^0.3.8"

jss@^9.3.3, jss@^9.7.0:
jss@^9.3.3:
version "9.8.5"
resolved "https://registry.yarnpkg.com/jss/-/jss-9.8.5.tgz#9ab86737e126de68180aba956a504421ba84bed4"
dependencies:
is-in-browser "^1.1.3"
symbol-observable "^1.1.0"
warning "^3.0.0"

jss@^9.7.0:
version "9.8.3"
resolved "https://registry.yarnpkg.com/jss/-/jss-9.8.3.tgz#399da571c4b2c8f4cf418ca7e8627e44fc287fc8"
dependencies:
Expand Down Expand Up @@ -5461,12 +5488,16 @@ react-lifecycles-compat@^3.0.2:
version "3.0.4"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"

react-popper@^0.10.0:
version "0.10.4"
resolved "https://registry.yarnpkg.com/react-popper/-/react-popper-0.10.4.tgz#af2a415ea22291edd504678d7afda8a6ee3295aa"
react-popper@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/react-popper/-/react-popper-1.0.0.tgz#b99452144e8fe4acc77fa3d959a8c79e07a65084"
dependencies:
babel-runtime "6.x.x"
create-react-context "^0.2.1"
popper.js "^1.14.1"
prop-types "^15.6.1"
typed-styles "^0.0.5"
warning "^3.0.0"

react-stripe-checkout@^2.6.3:
version "2.6.3"
Expand Down Expand Up @@ -5546,7 +5577,7 @@ realpath-native@^1.0.0:
dependencies:
util.promisify "^1.0.0"

"recompose@^0.26.0 || ^0.27.0":
recompose@^0.27.0:
version "0.27.1"
resolved "https://registry.yarnpkg.com/recompose/-/recompose-0.27.1.tgz#1a49e931f183634516633bbb4f4edbfd3f38a7ba"
dependencies:
Expand Down Expand Up @@ -6547,6 +6578,10 @@ type-is@~1.6.15, type-is@~1.6.16:
media-typer "0.3.0"
mime-types "~2.1.18"

typed-styles@^0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/typed-styles/-/typed-styles-0.0.5.tgz#a60df245d482a9b1adf9c06c078d0f06085ed1cf"

typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
Expand Down

0 comments on commit c524462

Please sign in to comment.