diff --git a/lib/apolloClient.ts b/lib/apolloClient.ts index 277ca5bb..1c637906 100644 --- a/lib/apolloClient.ts +++ b/lib/apolloClient.ts @@ -7,7 +7,7 @@ import { RestLink } from 'apollo-link-rest'; let apolloClient; const restLink = new RestLink({ - uri: 'https://demo.ckan.org/api/3/action/', + uri: getConfig().publicRuntimeConfig.DMS + '/api/3/action/', typePatcher: { Search: ( data: any, diff --git a/mocks/index.js b/mocks/index.js index 17c11e04..91561364 100644 --- a/mocks/index.js +++ b/mocks/index.js @@ -66,9 +66,7 @@ module.exports.initMocks = function () { nock('http://mock.ckan/api/3/action', { encodedQueryParams: true }) .persist() // 1. Call without query. - .get( - '/package_search?facet.field=organization&facet.field=groups&facet.field=tags&facet.field=res_format&facet.field=license_id&facet.limit=5' - ) + .get('/package_search?') .reply(200, { success: true, result: { @@ -80,9 +78,7 @@ module.exports.initMocks = function () { }, }) // 2. Call with `q=gdp` query. - .get( - '/package_search?q=gdp&facet.field=organization&facet.field=groups&facet.field=tags&facet.field=res_format&facet.field=license_id&facet.limit=5' - ) + .get('/package_search?q=gdp') .reply(200, { success: true, result: { diff --git a/next.config.js b/next.config.js index f788cd3b..577f4853 100644 --- a/next.config.js +++ b/next.config.js @@ -1,7 +1,37 @@ -module.exports = { - publicRuntimeConfig: { - graphqlEndpoint: - process.env.GRAPHQL_ENDPOINT || - 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn', - }, +const { PHASE_DEVELOPMENT_SERVER } = require('next/constants'); + +module.exports = (phase, { defaultConfig }) => { + const dms = process.env.DMS; + if (phase === PHASE_DEVELOPMENT_SERVER) { + if (dms) { + console.log('\nYou are running the app in dev mode 🌀'); + console.log( + 'Did you know that you can use mocked CKAN API? Just unset your `DMS` env var.' + ); + console.log('Happy coding ☀️\n'); + } else { + const mocks = require('./mocks'); + mocks.initMocks(); + console.log( + '\nYou have not defined any DMS API so we are activating the mocks ⚠️' + ); + console.log( + 'If you wish to run against your CKAN API, you can set `DMS` env var.' + ); + console.log( + 'For example, to run against demo ckan site: `DMS=https://demo.ckan.org`\n' + ); + } + + return { + publicRuntimeConfig: { + DMS: dms ? dms.replace(/\/?$/, '') : 'http://mock.ckan', + }, + }; + } + return { + publicRuntimeConfig: { + DMS: dms ? dms.replace(/\/?$/, '') : 'https://demo.ckan.org', + }, + }; }; diff --git a/pages/_app.tsx b/pages/_app.tsx index e91052ab..e872e296 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -4,13 +4,6 @@ import '../styles/index.css'; import { ApolloProvider } from '@apollo/react-hooks'; import { useApollo } from '../lib/apolloClient'; -// Setup mocks -// if (process.env.NODE_ENV === 'development') { -// const mocks = require('../mocks'); -// mocks.initMocks(); -// console.warn('You have activated the mocks.'); -// } - export default function MyApp({ Component, pageProps }) { const apolloClient = useApollo(pageProps.initialApolloState);