Skip to content

Commit

Permalink
Proxy dev api calls. Display page visits on website
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejmatu committed May 2, 2018
1 parent dea5690 commit 40e886c
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 9 deletions.
13 changes: 13 additions & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
const proxy = require("http-proxy-middleware");

module.exports = {
siteMetadata: {
title: 'Smoothielicious',
},
developMiddleware: app => {
app.use(
"/api",
proxy({
target: "http://localhost:9000",
pathRewrite: {
"/api": "",
},
})
);
},
plugins: [
'gatsby-plugin-react-helmet',
'gatsby-plugin-sass',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "1.0.0",
"dependencies": {
"basscss": "^8.0.4",
"concurrently": "^3.5.1",
"gatsby": "^1.9.252",
"gatsby-link": "^1.6.40",
"gatsby-plugin-netlify-cms": "^2.0.1",
Expand All @@ -30,7 +31,7 @@
"netlify-cms"
],
"scripts": {
"start": "npm run develop && npm run lambda-start",
"start": "concurrently 'npm run develop' 'npm run lambda-start'",
"build": "gatsby build && npm run lambda-build",
"develop": "gatsby develop",
"serve": "gatsby serve",
Expand Down
16 changes: 16 additions & 0 deletions src/components/PageCounter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import style from './style.scss';

function PageCounter({ count }) {
return (
<div className="counter">
{count ? (
<h4>Our shop is sooo popular, we already have {count} visits!</h4>
) : (
<h4>Loading...</h4>
)}
</div>
)
}

export default PageCounter
10 changes: 10 additions & 0 deletions src/components/PageCounter/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
div.counter {
padding: 0;
text-align: center;
background: #ffb93a;
color: white;

h4 {
margin: 10px;
}
}
32 changes: 26 additions & 6 deletions src/layouts/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
import React from 'react'
import PropTypes from 'prop-types'
import Helmet from 'react-helmet'
import PageCounter from '../components/PageCounter'
import '../style/main.scss'
import './index.scss'

const TemplateWrapper = ({ children, data }) => (
<div className="Layout">
<Helmet title={data.site.siteMetadata.title} />
{children()}
</div>
)
class TemplateWrapper extends React.Component {
state = {
visitCount: null
}

componentDidMount() {
fetch('/api/add-page-visit')
.then(res => res.json())
.then(data => {
this.setState({ visitCount: data.value.requests })
})
}

render() {
const { children, data } = this.props;

return (
<div className="Layout">
<Helmet title={data.site.siteMetadata.title} />
<PageCounter count={this.state.visitCount} />
{children()}
</div>
);
}
}

TemplateWrapper.propTypes = {
children: PropTypes.func,
Expand Down
5 changes: 4 additions & 1 deletion src/templates/index-page.template/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@

&__tags {
margin: 1.33em 0;
display: flex;
flex-wrap: wrap;
justify-content: center;
}

&__tag {
color: $color-blue;
border-radius: 20px;
font-size: 14px;
margin: 0 5px;
margin: 0 5px 5px;
border: 2px solid currentColor;
padding: 5px 10px;
}
Expand Down
73 changes: 72 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ [email protected]:
version "0.0.7"
resolved "https://registry.yarnpkg.com/ansi-html/-/ansi-html-0.0.7.tgz#813584021962a9e9e6fd039f940d12f56ca7859e"

ansi-regex@^0.2.0, ansi-regex@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-0.2.1.tgz#0d8e946967a3d8143f93e24e298525fc1b2235f9"

ansi-regex@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
Expand All @@ -181,6 +185,10 @@ ansi-regex@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"

ansi-styles@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.1.0.tgz#eaecbf66cd706882760b2f4691582b8f55d7a7de"

ansi-styles@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
Expand Down Expand Up @@ -1884,6 +1892,16 @@ chain-function@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/chain-function/-/chain-function-1.0.0.tgz#0d4ab37e7e18ead0bdc47b920764118ce58733dc"

[email protected]:
version "0.5.1"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.5.1.tgz#663b3a648b68b55d04690d49167aa837858f2174"
dependencies:
ansi-styles "^1.1.0"
escape-string-regexp "^1.0.0"
has-ansi "^0.1.0"
strip-ansi "^0.3.0"
supports-color "^0.2.0"

[email protected], chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
Expand Down Expand Up @@ -2234,6 +2252,10 @@ [email protected], commander@^2.11.0, commander@^2.9.0, commander@~2.15.0:
version "2.15.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"

[email protected]:
version "2.6.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.6.0.tgz#9df7e52fb2a0cb0fb89058ee80c3104225f37e1d"

[email protected], [email protected]:
version "2.9.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4"
Expand Down Expand Up @@ -2309,6 +2331,19 @@ concat-stream@^1.4.6, concat-stream@^1.4.7:
readable-stream "^2.2.2"
typedarray "^0.0.6"

concurrently@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-3.5.1.tgz#ee8b60018bbe86b02df13e5249453c6ececd2521"
dependencies:
chalk "0.5.1"
commander "2.6.0"
date-fns "^1.23.0"
lodash "^4.5.1"
rx "2.3.24"
spawn-command "^0.0.2-1"
supports-color "^3.2.3"
tree-kill "^1.1.0"

configstore@^3.0.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/configstore/-/configstore-3.1.2.tgz#c6f25defaeef26df12dd33414b001fe81a543f8f"
Expand Down Expand Up @@ -2658,6 +2693,10 @@ [email protected]:
version "0.0.4"
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-0.0.4.tgz#46e13ab9da8e309745c8d01ce547213ebdb2fe3f"

date-fns@^1.23.0:
version "1.29.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.29.0.tgz#12e609cdcb935127311d04d33334e2960a2a54e6"

date-now@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b"
Expand Down Expand Up @@ -3277,7 +3316,7 @@ escape-html@~1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"

[email protected], escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
[email protected], escape-string-regexp@^1.0.0, escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"

Expand Down Expand Up @@ -4687,6 +4726,12 @@ har-validator@~5.0.3:
ajv "^5.1.0"
har-schema "^2.0.0"

has-ansi@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-0.1.0.tgz#84f265aae8c0e6a88a12d7022894b7568894c62e"
dependencies:
ansi-regex "^0.2.0"

has-ansi@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
Expand Down Expand Up @@ -6334,6 +6379,10 @@ [email protected]:
version "4.11.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.11.1.tgz#a32106eb8e2ec8e82c241611414773c9df15f8bc"

lodash@^4.5.1:
version "4.17.10"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"

log-symbols@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-1.0.2.tgz#376ff7b58ea3086a0f09facc74617eca501e1a18"
Expand Down Expand Up @@ -9784,6 +9833,10 @@ rx-lite@*, rx-lite@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-4.0.8.tgz#0b1e11af8bc44836f04a6407e92da42467b79444"

[email protected]:
version "2.3.24"
resolved "https://registry.yarnpkg.com/rx/-/rx-2.3.24.tgz#14f950a4217d7e35daa71bbcbe58eff68ea4b2b7"

[email protected], safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"
Expand Down Expand Up @@ -10416,6 +10469,10 @@ sparkles@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/sparkles/-/sparkles-1.0.0.tgz#1acbbfb592436d10bbe8f785b7cc6f82815012c3"

spawn-command@^0.0.2-1:
version "0.0.2-1"
resolved "https://registry.yarnpkg.com/spawn-command/-/spawn-command-0.0.2-1.tgz#62f5e9466981c1b796dc5929937e11c9c6921bd0"

spdx-correct@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.0.0.tgz#05a5b4d7153a195bc92c3c425b69f3b2a9524c82"
Expand Down Expand Up @@ -10640,6 +10697,12 @@ [email protected], strip-ansi@^3.0.0, strip-ansi@^3.0.1:
dependencies:
ansi-regex "^2.0.0"

strip-ansi@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-0.3.0.tgz#25f48ea22ca79187f3174a4db8759347bb126220"
dependencies:
ansi-regex "^0.2.1"

strip-ansi@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f"
Expand Down Expand Up @@ -10710,6 +10773,10 @@ sum-up@^1.0.1:
dependencies:
chalk "^1.0.0"

supports-color@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-0.2.0.tgz#d92de2694eb3f67323973d7ae3d8b55b4c22190a"

supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
Expand Down Expand Up @@ -11024,6 +11091,10 @@ [email protected]:
semver "^4.3.3"
source-map-support "~0.2.8"

tree-kill@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.0.tgz#5846786237b4239014f05db156b643212d4c6f36"

trim-lines@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/trim-lines/-/trim-lines-1.1.0.tgz#9926d03ede13ba18f7d42222631fb04c79ff26fe"
Expand Down

0 comments on commit 40e886c

Please sign in to comment.