Skip to content

Commit 4d196e7

Browse files
committed
feat: Use no CDN for writepost and editpost
1 parent d11de11 commit 4d196e7

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
env:
3131
REACT_APP_API_HOST: 'https://v2.velog.io/'
3232
REACT_APP_GRAPHQL_HOST: 'https://v2cdn.velog.io/'
33+
REACT_APP_GRAPHQL_HOST_NOCDN: 'https://v2.velog.io/'
3334
PUBLIC_URL: 'https://static.velog.io/'
3435
REACT_APP_REDIS_HOST: ${{ secrets.REDIS_HOST }}
3536
CI: false

src/containers/write/MarkdownEditorContainer.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { Helmet } from 'react-helmet-async';
4242
import { toast } from 'react-toastify';
4343
import { usePrevious } from 'react-use';
4444
import { useTheme } from '../../lib/hooks/useTheme';
45+
import { noCdnClient } from '../../lib/graphql/client';
4546

4647
export type MarkdownEditorContainerProps = {};
4748

@@ -59,10 +60,14 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
5960
initialTitle,
6061
tags,
6162
} = useSelector((state: RootState) => state.write);
62-
const [writePost] = useMutation<WritePostResponse>(WRITE_POST);
63+
const [writePost] = useMutation<WritePostResponse>(WRITE_POST, {
64+
client: noCdnClient,
65+
});
6366
const [createPostHistory] =
6467
useMutation<CreatePostHistoryResponse>(CREATE_POST_HISTORY);
65-
const [editPost] = useMutation<EditPostResult>(EDIT_POST);
68+
const [editPost] = useMutation<EditPostResult>(EDIT_POST, {
69+
client: noCdnClient,
70+
});
6671

6772
const [lastSavedData, setLastSavedData] = useState({
6873
title: initialTitle,

src/containers/write/PublishActionButtonsContainer.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ import { useMutation, useApolloClient } from '@apollo/react-hooks';
1616
import { setHeadingId } from '../../lib/heading';
1717
import { useHistory } from 'react-router';
1818
import { toast } from 'react-toastify';
19+
import { noCdnClient } from '../../lib/graphql/client';
1920

2021
type PublishActionButtonsContainerProps = {};
2122

22-
const PublishActionButtonsContainer: React.FC<PublishActionButtonsContainerProps> = () => {
23+
const PublishActionButtonsContainer: React.FC<
24+
PublishActionButtonsContainerProps
25+
> = () => {
2326
const history = useHistory();
2427
const client = useApolloClient();
2528

@@ -49,8 +52,12 @@ const PublishActionButtonsContainer: React.FC<PublishActionButtonsContainerProps
4952
dispatch(closePublish());
5053
}, [dispatch]);
5154

52-
const [writePost] = useMutation<WritePostResponse>(WRITE_POST);
53-
const [editPost] = useMutation<EditPostResult>(EDIT_POST);
55+
const [writePost] = useMutation<WritePostResponse>(WRITE_POST, {
56+
client: noCdnClient,
57+
});
58+
const [editPost] = useMutation<EditPostResult>(EDIT_POST, {
59+
client: noCdnClient,
60+
});
5461

5562
const variables = {
5663
title: options.title,

src/lib/graphql/client.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,34 @@ const host =
77
? '/'
88
: process.env.REACT_APP_GRAPHQL_HOST) || '/';
99

10+
const noCdnHost =
11+
(process.env.NODE_ENV === 'development'
12+
? '/'
13+
: process.env.REACT_APP_GRAPHQL_HOST_NOCDN) || '/';
14+
15+
const cache = new InMemoryCache().restore((window as any).__APOLLO_STATE__);
16+
1017
const graphqlURI = host.concat('graphql');
18+
const noCdnGraphqlURI = noCdnHost.concat('graphql');
19+
1120
const link = createHttpLink({
1221
uri: graphqlURI,
1322
credentials: 'include',
1423
});
1524

25+
const noCdnLink = createHttpLink({
26+
uri: noCdnGraphqlURI,
27+
credentials: 'include',
28+
});
29+
1630
const client = new ApolloClient({
1731
link,
18-
cache: new InMemoryCache().restore((window as any).__APOLLO_STATE__),
32+
cache,
33+
});
34+
35+
export const noCdnClient = new ApolloClient({
36+
link: noCdnLink,
37+
cache,
1938
});
2039

2140
(window as any).client = client;

0 commit comments

Comments
 (0)