Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create stock movement uses hardcoded openboxes on link #1600

Closed
lorranpego opened this issue Apr 21, 2020 · 2 comments
Closed

Create stock movement uses hardcoded openboxes on link #1600

lorranpego opened this issue Apr 21, 2020 · 2 comments

Comments

@lorranpego
Copy link

When clicking on Inbound -> Create Inbound Stock Movement it shows Not found. Resource not found message
openboxes

The calls to /api/getAppContext and /api/localizations uses a hardcoded openboxes/ in front of it
Screenshot_20200421_145413

Other calls do not have the hardcoded openboxes/
Screenshot_20200421_145427

Other Information:
Grails Version: 1.3.9
Application version: 0.8.11
Branch: master
Build Number: v0.8.11
Environment: production

@jmiranda
Copy link
Member

@lorranpego Thanks for the awesome bug report!

We have a ticket to enable a configurable context path that we are planning to introduce in 0.9.x (when we upgrade to Grails 3), but I'll see if there's some way to deal with this in the short-term.

At the moment, the easiest (only) way to deal with this is to deploy the WAR as openboxes.war. I know that's a bummer since you probably want to white label your server, but that's the best we can do with the current version.

Additional Context
The HTML files that are served by Tomcat (or whatever app server you're using) use the app context path that is configured when the war file is deployed (so /openboxes for openboxes.war). Most if not all of the GSP files in OpenBoxes use ${request.contextPath} when linking resources like images, css, and javascript so you can deploy OpenBoxes as wms.war, openboxes.war, ROOT.war and all web resources will be linked properly (using /wms, /openboxes, /).

However, there's no way to pass this deploy-time context path to the React apps because they are compiled before the application is deployed. So imagine you deploy the WAR file as "myopenboxes.war" and load a page that initializes a React app. The React app has several API endpoints that it calls to get / update date. But how would you pass that new context path (myopenboxes) to React so that it can reference the APIs properly.

There's potentially one very hacky way of doing this in the short term, since we use a GSP to load the React page. And that is to include some javascript to set a global variable that will be used by the React app.

So I think the following (or something similar) would probably work assuming that the React doesn't do anything do exclude scope outside of the application resources.

grails-template.html

<script>
    const contextPath = "${request.contextPath}"
</script>

And then later in a React JSX file (for example)

AddItemsPage.jsx

  /**
   * Fetches 2nd step data from current stock movement.
   * @public
   */
  fetchLineItems() {
    const url = contextPath + `/api/stockMovements/${this.state.values.stockMovementId}/stockMovementItems?stepNumber=2`;

    return apiClient.get(url)
      .then((response) => {
        this.setLineItems(response);
      })
      .catch(err => err);
 }

I don't know React well enough to conclude whether this will work or not. But I'll see if we can get it to work properly in version 0.8.12.

@lorranpego
Copy link
Author

Thanks @jmiranda,
Yes, I got it working this way, I deployed using openboxes.war and it worked.

That is how I knew there was some bug there.

Since there is already a ticket, I will close the Issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants