Skip to content

Commit

Permalink
chore: fix envs and add base path
Browse files Browse the repository at this point in the history
  • Loading branch information
apotdevin committed Apr 14, 2020
1 parent 115266b commit 00c7851
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 31 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
.env
.vscode
.storybook
CHANGELOG.md
CHANGELOG.md
.elasticbeanstalk/*
.ebextensions/*
30 changes: 20 additions & 10 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -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',
},
});
7 changes: 5 additions & 2 deletions src/api/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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;
};

Expand Down
9 changes: 6 additions & 3 deletions src/api/helpers/logger.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -33,7 +36,7 @@ const combinedFormat =
);

export const logger = createLogger({
level: envConfig.logLevel,
level: logLevel,
format: combinedFormat,
transports: [new transports.Console()],
});
7 changes: 5 additions & 2 deletions src/api/schemas/query/hodlhodl/getCountries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -13,7 +16,7 @@ export const getCountries = {
await requestLimiter(context.ip, 'getCountries');

const headers = {
Authorization: `Bearer ${envConfig.hodlKey}`,
Authorization: `Bearer ${hodlKey}`,
};

try {
Expand Down
7 changes: 5 additions & 2 deletions src/api/schemas/query/hodlhodl/getCurrencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -13,7 +16,7 @@ export const getCurrencies = {
await requestLimiter(context.ip, 'getCurrencies');

const headers = {
Authorization: `Bearer ${envConfig.hodlKey}`,
Authorization: `Bearer ${hodlKey}`,
};

try {
Expand Down
5 changes: 0 additions & 5 deletions src/api/utils/envConfig.ts

This file was deleted.

6 changes: 5 additions & 1 deletion src/components/auth/views/Password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +15,9 @@ interface PasswordProps {
loading: boolean;
}

const { publicRuntimeConfig } = getConfig();
const { nodeEnv } = publicRuntimeConfig;

const PasswordInput = ({
isPass = '',
setPass,
Expand All @@ -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 (
<>
Expand Down
11 changes: 7 additions & 4 deletions src/components/link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -49,6 +50,9 @@ interface LinkProps {
noStyling?: boolean;
}

const { publicRuntimeConfig } = getConfig();
const { basePath } = publicRuntimeConfig;

export const Link = ({
children,
href,
Expand All @@ -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 (
Expand All @@ -74,9 +78,8 @@ export const Link = ({
}

return (
<RouterLink href={to}>
<RouterLink href={`${basePath}${to}`}>
<CorrectLink {...props}>{children}</CorrectLink>
</RouterLink>
);
// }
};
6 changes: 5 additions & 1 deletion src/layouts/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,6 +92,9 @@ const Version = styled.div`
margin-left: 8px;
`;

const { publicRuntimeConfig } = getConfig();
const { npmVersion } = publicRuntimeConfig;

export const Footer = () => {
const { loggedIn } = useAccount();
return (
Expand All @@ -101,7 +105,7 @@ export const Footer = () => {
<Link to={'/'}>
<Title>ThunderHub</Title>
</Link>
<Version>{'0.3.0'}</Version>
<Version>{npmVersion}</Version>
</Line>
<SideText>
Open-source lightning node manager to control and monitor your LND
Expand Down

0 comments on commit 00c7851

Please sign in to comment.