Repository: parcel-bundler/parcel
Pull request #5108 (2020-09-06 20:54:32)

add recognition of .proxyrc.json file, also
<!---
Thanks for filing a pull request 😄 ! Before you submit, please read the following:

Search open/closed issues before submitting since someone might have pushed the same thing before!
-->

# ↪️ Pull Request

<!---
Provide a general summary of the pull request here
Please look for any issues that this PR resolves and tag them in the PR.
-->

This PR adds the ability to use `.proxyrc.json` as well as `.proxyrc` and `.proxyrc.js`.

## 💻 Examples

<!-- Examples help us understand the requested feature better -->

 The behavior is identical to `.proxyrc`, but this allows editors to recognize the syntax.

## 🚨 Test instructions

<!-- In case it is impossible (or too hard) to reliably test this feature/fix with unit tests, please provide test instructions! -->

There is an integration test added along side the other two use cases.

## ✔️ PR Todo

- [x] Added/updated unit tests for this change
- [x] Filled out test instructions (In case there aren't any unit tests)
- [x] Included links to related issues/PRs (not relevant)


height[bot]: > Link [Height](https://parcel.height.app) tasks by mentioning a task ID in the pull request title or description, commit messages, or comments.
>
> 💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.
<!-- Sent by Height -->

Patch:
diff --git a/packages/reporters/dev-server/src/Server.js b/packages/reporters/dev-server/src/Server.js
index 022b628af..1512c57a4 100644
--- a/packages/reporters/dev-server/src/Server.js
+++ b/packages/reporters/dev-server/src/Server.js
@@ -308,6 +308,7 @@ export default class Server extends EventEmitter {
     const pkg = await loadConfig(this.options.inputFS, fileInRoot, [
       '.proxyrc.js',
       '.proxyrc',
+      '.proxyrc.json',
     ]);
 
     if (!pkg || !pkg.config || !pkg.files) {
@@ -326,7 +327,7 @@ export default class Server extends EventEmitter {
         return this;
       }
       cfg(app);
-    } else if (filename === '.proxyrc') {
+    } else if (filename === '.proxyrc' || filename === '.proxyrc.json') {
       if (typeof cfg !== 'object') {
         this.options.logger.warn({
           message:


Test patch:
diff --git a/packages/core/integration-tests/test/integration/proxyrc-json/.proxyrc.json b/packages/core/integration-tests/test/integration/proxyrc-json/.proxyrc.json
new file mode 100644
index 000000000..02a783fcd
--- /dev/null
+++ b/packages/core/integration-tests/test/integration/proxyrc-json/.proxyrc.json
@@ -0,0 +1,5 @@
+{
+  "/api": {
+    "target": "http://localhost:9753"
+  }
+}
diff --git a/packages/core/integration-tests/test/integration/proxyrc-json/index.js b/packages/core/integration-tests/test/integration/proxyrc-json/index.js
new file mode 100644
index 000000000..313f42810
--- /dev/null
+++ b/packages/core/integration-tests/test/integration/proxyrc-json/index.js
@@ -0,0 +1,3 @@
+module.exports = function () {
+  return 'Hello, Parcel.js!';
+};
diff --git a/packages/core/integration-tests/test/integration/proxyrc-json/yarn.lock b/packages/core/integration-tests/test/integration/proxyrc-json/yarn.lock
new file mode 100644
index 000000000..fb57ccd13
--- /dev/null
+++ b/packages/core/integration-tests/test/integration/proxyrc-json/yarn.lock
@@ -0,0 +1,4 @@
+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
+
+
diff --git a/packages/core/integration-tests/test/proxy.js b/packages/core/integration-tests/test/proxy.js
index 268e8404b..637500fe6 100644
--- a/packages/core/integration-tests/test/proxy.js
+++ b/packages/core/integration-tests/test/proxy.js
@@ -97,6 +97,32 @@ describe('proxy', function() {
     assert.equal(data, 'Request URL: /api/get');
   });
 
+  it('should handle proxy table written in .proxyrc.json', async function() {
+    let dir = path.join(__dirname, 'integration/proxyrc-json');
+    inputFS.chdir(dir);
+
+    let port = await getPort();
+    let b = bundler(path.join(dir, 'index.js'), {
+      config,
+      serve: {
+        https: false,
+        port: port,
+        host: 'localhost',
+      },
+    });
+
+    subscription = await b.watch();
+    await getNextBuild(b);
+
+    server = apiServer();
+
+    let data = await get('/index.js', port);
+    assert.notEqual(data, 'Request URL: /index.js');
+
+    data = await get('/api/get', port);
+    assert.equal(data, 'Request URL: /api/get');
+  });
+
   it('should handle proxy table written in .proxyrc.js', async function() {
     let dir = path.join(__dirname, 'integration/proxyrc-js');
     inputFS.chdir(dir);