adobe / aem-spa-project-archetype

Maven Archetype for creating new AEM SPA projects
Apache License 2.0
61 stars 32 forks source link

Get rid of the CustomModelClient and set a server proxy #74

Closed pfauchere closed 4 years ago

pfauchere commented 5 years ago

A cleaner solution could be to use: https://facebook.github.io/create-react-app/docs/proxying-api-requests-in-development#configuring-the-proxy-manually

ex: react-app/src/setupProxy.js

const proxy = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(proxy(
      ['**/*.model.json', '**/*.jpg', '**/*.jpeg', '**/*.png'], 
      { 
          target: process.env.REACT_APP_API_HOST,
          auth: process.env.REACT_APP_AEM_ADMIN_AUTH
    }
    ));
};

By making this change we should be able to get rid of the following conditional step [0] and potentially the {{CustomModelClient}}. If necessary, the {{CustomModelClient}} could potentially be reintroduced in conjunction with an SSR setup.

[0] https://github.com/adobe/aem-spa-project-archetype/blob/development/src/main/resources/archetype-resources/react-app/src/index.js#L42-L47

pfauchere commented 5 years ago

cc @godanny86

pfauchere commented 5 years ago

issue tracked internally by CQ-4266178

ittaibaratz commented 5 years ago

Note a React developer may use static assets in his project, so I would set the proxy as follows to allow assets hosted by webpack:

app.use(proxy(
      ['**/*.model.json', '/content/**/*.jpg', '/content/**/*.jpeg', '/content/**/*.png'],