Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const {createProxyMiddleware} = require('http-proxy-middleware');

module.exports = function(app) {
app.use(createProxyMiddleware('/api', {
target: 'http://localhost:9753/',
pathRewrite: {
'^/api': ''
}
}));
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function () {
return 'Hello, Parcel.js!';
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


26 changes: 26 additions & 0 deletions packages/core/integration-tests/test/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,30 @@ describe('proxy', function () {
data = await get('/api/get', port);
assert.equal(data, 'Request URL: /get');
});

it('should handle proxy table written in .proxyrc.cjs', async function () {
let dir = path.join(__dirname, 'integration/proxyrc-cjs');
inputFS.chdir(dir);

let port = await getPort();
let b = bundler(path.join(dir, 'index.js'), {
config,
serveOptions: {
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: /get');
});
});
7 changes: 3 additions & 4 deletions packages/reporters/dev-server/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export default class Server {
const pkg = await loadConfig(
this.options.inputFS,
fileInRoot,
['.proxyrc.js', '.proxyrc', '.proxyrc.json'],
['.proxyrc.cjs', '.proxyrc.js', '.proxyrc', '.proxyrc.json'],
this.options.projectRoot,
);

Expand All @@ -397,11 +397,10 @@ export default class Server {
const cfg = pkg.config;
const filename = path.basename(pkg.files[0].filePath);

if (filename === '.proxyrc.js') {
if (filename === '.proxyrc.js' || filename === '.proxyrc.cjs') {
if (typeof cfg !== 'function') {
this.options.logger.warn({
message:
"Proxy configuration file '.proxyrc.js' should export a function. Skipping...",
message: `Proxy configuration file '${filename}' should export a function. Skipping...`,
});
return this;
}
Expand Down