From 00c78513ec3611a7a3bb39732abfa35abcffbbe6 Mon Sep 17 00:00:00 2001 From: AP Date: Tue, 14 Apr 2020 08:25:58 +0200 Subject: [PATCH] chore: fix envs and add base path --- .dockerignore | 4 ++- next.config.js | 30 ++++++++++++------- src/api/helpers/helpers.ts | 7 +++-- src/api/helpers/logger.ts | 9 ++++-- .../schemas/query/hodlhodl/getCountries.ts | 7 +++-- .../schemas/query/hodlhodl/getCurrencies.ts | 7 +++-- src/api/utils/envConfig.ts | 5 ---- src/components/auth/views/Password.tsx | 6 +++- src/components/link/Link.tsx | 11 ++++--- src/layouts/footer/Footer.tsx | 6 +++- 10 files changed, 61 insertions(+), 31 deletions(-) delete mode 100644 src/api/utils/envConfig.ts diff --git a/.dockerignore b/.dockerignore index d4e78559..2d22caff 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,4 +10,6 @@ .env .vscode .storybook -CHANGELOG.md \ No newline at end of file +CHANGELOG.md +.elasticbeanstalk/* +.ebextensions/* \ No newline at end of file diff --git a/next.config.js b/next.config.js index 2cb7b5c7..0201b93d 100644 --- a/next.config.js +++ b/next.config.js @@ -1,13 +1,23 @@ -const { parsed: localEnv } = require('dotenv').config(); -const webpack = require('webpack'); -module.exports = { - webpack: config => { - config.plugins.push(new webpack.EnvironmentPlugin(localEnv)); - return config; - }, -}; - +const dotEnvResult = require('dotenv').config(); const withBundleAnalyzer = require('@next/bundle-analyzer')({ enabled: process.env.ANALYZE === 'true', }); -module.exports = withBundleAnalyzer({}); + +if (dotEnvResult.error) { + throw dotEnvResult.error; +} + +module.exports = withBundleAnalyzer({ + poweredByHeader: false, + assetPrefix: process.env.BASE_PATH || '', + serverRuntimeConfig: { + nodeEnv: process.env.NODE_ENV || 'development', + logLevel: process.env.LOG_LEVEL || 'silly', + hodlKey: process.env.HODL_KEY || '', + }, + publicRuntimeConfig: { + nodeEnv: process.env.NODE_ENV || 'development', + basePath: process.env.BASE_PATH || '', + npmVersion: process.env.npm_package_version || '0.0.0', + }, +}); diff --git a/src/api/helpers/helpers.ts b/src/api/helpers/helpers.ts index 6ad26a18..6a5f2ca3 100644 --- a/src/api/helpers/helpers.ts +++ b/src/api/helpers/helpers.ts @@ -1,5 +1,8 @@ import { authenticatedLndGrpc } from 'ln-service'; -import { envConfig } from '../utils/envConfig'; +import getConfig from 'next/config'; + +const { serverRuntimeConfig } = getConfig(); +const { nodeEnv } = serverRuntimeConfig; export const getIp = (req: any) => { if (!req || !req.headers) { @@ -9,7 +12,7 @@ export const getIp = (req: any) => { const before = forwarded ? forwarded.split(/, /)[0] : req.connection.remoteAddress; - const ip = envConfig.env === 'development' ? '1.2.3.4' : before; + const ip = nodeEnv === 'development' ? '1.2.3.4' : before; return ip; }; diff --git a/src/api/helpers/logger.ts b/src/api/helpers/logger.ts index e61b1716..2beefb79 100644 --- a/src/api/helpers/logger.ts +++ b/src/api/helpers/logger.ts @@ -1,9 +1,12 @@ import { createLogger, format, transports } from 'winston'; +import getConfig from 'next/config'; import path from 'path'; -import { envConfig } from '../utils/envConfig'; + +const { serverRuntimeConfig } = getConfig(); +const { logLevel, nodeEnv } = serverRuntimeConfig; const combinedFormat = - envConfig.env === 'development' + nodeEnv === 'development' ? format.combine( format.label({ label: path.basename( @@ -33,7 +36,7 @@ const combinedFormat = ); export const logger = createLogger({ - level: envConfig.logLevel, + level: logLevel, format: combinedFormat, transports: [new transports.Console()], }); diff --git a/src/api/schemas/query/hodlhodl/getCountries.ts b/src/api/schemas/query/hodlhodl/getCountries.ts index 9ab1c52d..5756a97f 100644 --- a/src/api/schemas/query/hodlhodl/getCountries.ts +++ b/src/api/schemas/query/hodlhodl/getCountries.ts @@ -4,7 +4,10 @@ import { requestLimiter } from '../../../helpers/rateLimiter'; import { logger } from '../../../helpers/logger'; import { appUrls } from '../../../utils/appUrls'; import { HodlCountryType } from '../../types/HodlType'; -import { envConfig } from '../../../utils/envConfig'; +import getConfig from 'next/config'; + +const { serverRuntimeConfig } = getConfig(); +const { hodlKey } = serverRuntimeConfig; export const getCountries = { type: new GraphQLList(HodlCountryType), @@ -13,7 +16,7 @@ export const getCountries = { await requestLimiter(context.ip, 'getCountries'); const headers = { - Authorization: `Bearer ${envConfig.hodlKey}`, + Authorization: `Bearer ${hodlKey}`, }; try { diff --git a/src/api/schemas/query/hodlhodl/getCurrencies.ts b/src/api/schemas/query/hodlhodl/getCurrencies.ts index e5794dca..cf6a7bba 100644 --- a/src/api/schemas/query/hodlhodl/getCurrencies.ts +++ b/src/api/schemas/query/hodlhodl/getCurrencies.ts @@ -4,7 +4,10 @@ import { requestLimiter } from '../../../helpers/rateLimiter'; import { logger } from '../../../helpers/logger'; import { appUrls } from '../../../utils/appUrls'; import { HodlCurrencyType } from '../../types/HodlType'; -import { envConfig } from '../../../utils/envConfig'; +import getConfig from 'next/config'; + +const { serverRuntimeConfig } = getConfig(); +const { hodlKey } = serverRuntimeConfig; export const getCurrencies = { type: new GraphQLList(HodlCurrencyType), @@ -13,7 +16,7 @@ export const getCurrencies = { await requestLimiter(context.ip, 'getCurrencies'); const headers = { - Authorization: `Bearer ${envConfig.hodlKey}`, + Authorization: `Bearer ${hodlKey}`, }; try { diff --git a/src/api/utils/envConfig.ts b/src/api/utils/envConfig.ts deleted file mode 100644 index 07fcb42e..00000000 --- a/src/api/utils/envConfig.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const envConfig = { - env: process.env.NODE_ENV || 'development', - logLevel: process.env.LOG_LEVEL || 'silly', - hodlKey: process.env.HODL_KEY, -}; diff --git a/src/components/auth/views/Password.tsx b/src/components/auth/views/Password.tsx index e2438c49..7ca66e67 100644 --- a/src/components/auth/views/Password.tsx +++ b/src/components/auth/views/Password.tsx @@ -6,6 +6,7 @@ import { Input } from '../../input/Input'; import { Line, CheckboxText } from '../Auth.styled'; import { LoadingBar } from '../../loadingBar/LoadingBar'; import { Checkbox } from '../../checkbox/Checkbox'; +import getConfig from 'next/config'; interface PasswordProps { isPass?: string; @@ -14,6 +15,9 @@ interface PasswordProps { loading: boolean; } +const { publicRuntimeConfig } = getConfig(); +const { nodeEnv } = publicRuntimeConfig; + const PasswordInput = ({ isPass = '', setPass, @@ -22,7 +26,7 @@ const PasswordInput = ({ }: PasswordProps) => { const [checked, setChecked] = useState(false); const strength = (100 * Math.min(zxcvbn(isPass).guesses_log10, 40)) / 40; - const needed = process.env.NODE_ENV !== 'development' ? 1 : checked ? 10 : 20; + const needed = nodeEnv === 'development' ? 1 : checked ? 10 : 20; return ( <> diff --git a/src/components/link/Link.tsx b/src/components/link/Link.tsx index b8a29b7f..bd072650 100644 --- a/src/components/link/Link.tsx +++ b/src/components/link/Link.tsx @@ -3,6 +3,7 @@ import styled, { css } from 'styled-components'; import { textColor, linkHighlight } from '../../styles/Themes'; import { ThemeSet } from 'styled-theming'; import RouterLink from 'next/link'; +import getConfig from 'next/config'; interface StyledProps { fontColor?: string | ThemeSet; @@ -11,7 +12,7 @@ interface StyledProps { fullWidth?: boolean; } -const StyledALink = styled.a` +const StyledLink = styled.a` cursor: pointer; color: ${({ fontColor, inheritColor }: StyledProps) => inheritColor ? 'inherit' : fontColor ?? textColor}; @@ -49,6 +50,9 @@ interface LinkProps { noStyling?: boolean; } +const { publicRuntimeConfig } = getConfig(); +const { basePath } = publicRuntimeConfig; + export const Link = ({ children, href, @@ -63,7 +67,7 @@ export const Link = ({ if (!href && !to) return null; - const CorrectLink = noStyling ? NoStyling : StyledALink; + const CorrectLink = noStyling ? NoStyling : StyledLink; if (href) { return ( @@ -74,9 +78,8 @@ export const Link = ({ } return ( - + {children} ); - // } }; diff --git a/src/layouts/footer/Footer.tsx b/src/layouts/footer/Footer.tsx index ecf4978b..fde73eae 100644 --- a/src/layouts/footer/Footer.tsx +++ b/src/layouts/footer/Footer.tsx @@ -13,6 +13,7 @@ import { useAccount } from '../../context/AccountContext'; import RouterLink from 'next/link'; import { HomeButton } from '../../views/homepage/HomePage.styled'; import { Zap } from '../../components/generic/Icons'; +import getConfig from 'next/config'; const FooterStyle = styled.div` padding: 40px 0; @@ -91,6 +92,9 @@ const Version = styled.div` margin-left: 8px; `; +const { publicRuntimeConfig } = getConfig(); +const { npmVersion } = publicRuntimeConfig; + export const Footer = () => { const { loggedIn } = useAccount(); return ( @@ -101,7 +105,7 @@ export const Footer = () => { ThunderHub - {'0.3.0'} + {npmVersion} Open-source lightning node manager to control and monitor your LND