Dynamic string substitution with Webpack

There's one minor improvement we must make before we can do E2E testing with the API backend. At the moment, we are hard-coding the URL for our production API endpoint (localhost:8080), even though during the test, the testing URL (localhost:8888) will be used. Therefore, we need to replace this with a placeholder that we can override during build time.

First, in src/components/registration-form/index.jsx, replace the following line:

const request = new Request('http://localhost:8080/users/', {})

With this one:

const request = new Request('http://%%API_SERVER_HOST%%:%%API_SERVER_PORT%%/users/', {})
We are using %% to mark our placeholder because it's a relatively uncommon sequence of characters. You ...

Get Building Enterprise JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.