Skip to content

Commit

Permalink
Merge pull request #2 from samburney/appConfig
Browse files Browse the repository at this point in the history
Move hard coded config to config files
  • Loading branch information
lucasgdb authored Jan 3, 2020
2 parents a08b500 + ad93f71 commit e4be645
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/backend/src/config/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"mongo": {
"host": "localhost",
"port": "27017"
}
}
3 changes: 2 additions & 1 deletion packages/backend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const mongoose = require('mongoose');
const cors = require('cors');

const app = express();
const appConfig = require('./config/app.json');

mongoose.connect('mongodb://localhost:27017/url-shortener', {
mongoose.connect(`mongodb://${appConfig.mongo.host}:${appConfig.mongo.port}/url-shortener`, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/src/config/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"baseURL": "http://127.0.0.1:3000/"
}
13 changes: 7 additions & 6 deletions packages/frontend/src/pages/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
import { CopyToClipboard } from 'react-copy-to-clipboard';

const engine = new Client();
const appConfig = require('~/config/app.json');

export default function Home({ darkTheme }) {
const [originalURL, setOriginalURL] = useState('');
Expand Down Expand Up @@ -392,16 +393,16 @@ export default function Home({ darkTheme }) {
<Paragraph3>
Shortened URL:{' '}
<StyledLink
href={`http://127.0.0.1:3000/${shortenedURL}`}
href={`${appConfig.baseURL}${shortenedURL}`}
target="_blank"
>
http://127.0.0.1:3000/{shortenedURL}
{appConfig.baseURL}{shortenedURL}
</StyledLink>
</Paragraph3>
</HeadingLevel>

<CopyToClipboard
text={`http://127.0.0.1:3000/${shortenedURL}`}
text={`${appConfig.baseURL}${shortenedURL}`}
>
<StatefulPopover
placement={PLACEMENT.bottom}
Expand Down Expand Up @@ -501,10 +502,10 @@ export default function Home({ darkTheme }) {
</p>

<StyledLink
href={`http://127.0.0.1:3000/${URL.shortenedURL}`}
href={`${appConfig.baseURL}${URL.shortenedURL}`}
target="_blank"
>
http://127.0.0.1:3000/
{appConfig.baseURL}
{URL.shortenedURL}
</StyledLink>
</div>
Expand All @@ -517,7 +518,7 @@ export default function Home({ darkTheme }) {
}}
>
<CopyToClipboard
text={`http://127.0.0.1:3000/${URL.shortenedURL}`}
text={`${appConfig.baseURL}${URL.shortenedURL}`}
>
<StatefulPopover
placement={
Expand Down

0 comments on commit e4be645

Please sign in to comment.