Skip to content

Commit

Permalink
Make the Rollbar endpoint configurable to support self hosted Rollbar…
Browse files Browse the repository at this point in the history
… instances. (#43)
  • Loading branch information
Derrick Cheng authored and brandondoran committed Mar 20, 2018
1 parent 3b8f2b0 commit cfb980d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ If `false`, success and warning messages will be logged to the console for each
#### `ignoreErrors: boolean` **(default: `false`)**
Set to `true` to bypass adding upload errors to the webpack compilation. Do this if you do not want to fail the build when sourcemap uploads fail. If you do not want to fail the build but you do want to see the failures as warnings, make sure `silent` option is set to `false`.

#### `rollbarEndpoint: string` **(default: `https://api.rollbar.com/api/1/sourcemap`)**
A string defining the Rollbar API endpoint to upload the sourcemaps to. It can be used for self-hosted Rollbar instances.

## App Configuration
- The web app should have [rollbar-browser](https://github.com/rollbar/rollbar.js) installed and configured for webpack as described [here](https://github.com/rollbar/rollbar.js/tree/master/examples/webpack#using-rollbar-with-webpack).
- See the [Rollbar source map](https://rollbar.com/docs/source-maps/) documentation
Expand Down
6 changes: 4 additions & 2 deletions src/RollbarSourceMapPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ class RollbarSourceMapPlugin {
publicPath,
includeChunks = [],
silent = false,
ignoreErrors = false
ignoreErrors = false,
rollbarEndpoint = ROLLBAR_ENDPOINT
}) {
this.accessToken = accessToken;
this.version = version;
this.publicPath = publicPath;
this.includeChunks = [].concat(includeChunks);
this.silent = silent;
this.ignoreErrors = ignoreErrors;
this.rollbarEndpoint = rollbarEndpoint;
}

afterEmit(compilation, cb) {
Expand Down Expand Up @@ -72,7 +74,7 @@ class RollbarSourceMapPlugin {
}

uploadSourceMap(compilation, { sourceFile, sourceMap }, cb) {
const req = request.post(ROLLBAR_ENDPOINT, (err, res, body) => {
const req = request.post(this.rollbarEndpoint, (err, res, body) => {
if (!err && res.statusCode === 200) {
if (!this.silent) {
console.info(`Uploaded ${sourceMap} to Rollbar`); // eslint-disable-line no-console
Expand Down
12 changes: 12 additions & 0 deletions test/RollbarSourceMapPlugin.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import expect, { isSpy, spyOn, createSpy } from 'expect';
import nock from 'nock';
import RollbarSourceMapPlugin from '../src/RollbarSourceMapPlugin';
import { ROLLBAR_ENDPOINT } from '../src/constants';

describe('RollbarSourceMapPlugin', function() {
beforeEach(function() {
Expand Down Expand Up @@ -65,6 +66,17 @@ describe('RollbarSourceMapPlugin', function() {
const plugin = new RollbarSourceMapPlugin(options);
expect(plugin).toInclude({ includeChunks: ['foo', 'bar'] });
});

it('should default rollbarEndpoint to ROLLBAR_ENDPOINT constant', function() {
expect(this.plugin).toInclude({ rollbarEndpoint: ROLLBAR_ENDPOINT });
});

it('should access string value for rollbarEndpoint', function() {
const customEndpoint = 'https://api.rollbar.custom.com/api/1/sourcemap';
const options = Object.assign({}, this.options, { rollbarEndpoint: customEndpoint });
const plugin = new RollbarSourceMapPlugin(options);
expect(plugin).toInclude({ rollbarEndpoint: customEndpoint });
});
});

describe('apply', function() {
Expand Down

0 comments on commit cfb980d

Please sign in to comment.