react-storefront icon indicating copy to clipboard operation
react-storefront copied to clipboard

How to disable mock connector code

Open rv-nath opened this issue 2 years ago • 3 comments

Bug report

Mock connector code executes, even after I comment the connector line in next.config.js.

Describe the bug

After reading the official documentation (as presented here), I commented out the connector line in next.config.js.

const webpack = require('webpack')
const withReactStorefront = require('react-storefront/plugins/withReactStorefront')
require('dotenv').config()

module.exports = withReactStorefront({
  target: 'serverless',
  //connector: 'react-storefront/mock-connector',
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack })=> {
    config.plugins.push(
      new webpack.optimize.LimitChunkCountPlugin({
        maxChunks: 1,
      })
    )
    config.module.rules.push({
      test: /\.(png|jpg|gif|svg)$/i,
      use: [
        {
          loader: 'url-loader',
          options: {
            limit: 8192
          }
        }
      ]
    })
    return config
  },
})

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a new project using storefront template 2.Edit next.config.js by removing the connector line 3.do npm install to download all dependencies
  2. npm start

Expected behavior

The program should successfully compile and the connector API such as /api/session, and /api/routes should not be invoked.

Screenshots

image

Web console logs indicating calls from mock-connector code image

If applicable, add screenshots to help explain your problem.

System information

  • OS: macOS
  • Browser chrome
  • Version of React Storefront: 8.17.4

Additional context

Add any other context about the problem here.

rv-nath avatar Aug 30 '21 15:08 rv-nath

On firefox browser, it throws up the error on the screen itself. image

rv-nath avatar Aug 30 '21 15:08 rv-nath

I ran into this issue as well. The docs are correct as far as I can tell, but it's hard to understand what they're suggesting. What I did was remove all imports of react-storefront-connector from my code. After you've done that, you can import handlers you've created yourself, or implement your logic directly in each "api page."

I'm importing my handlers so that I can potentially turn my implementation into a connector.

For any maintainers, I think it would be great if this configuration could accept null or undefined values for the connector!

jcuffe avatar Oct 19 '21 18:10 jcuffe

OK. I provided a dummy implementation for routes.api by returning an empty json. This solved my problem. However, your approach seems better, as it optimizes by removing unneeded imports.

rv-nath avatar Oct 23 '21 10:10 rv-nath