Skip to content

Commit

Permalink
added some examples
Browse files Browse the repository at this point in the history
refs #4
  • Loading branch information
gkostov committed Mar 31, 2021
1 parent 50f1312 commit 7c9242e
Show file tree
Hide file tree
Showing 10 changed files with 5,047 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions examples/stack-traces-to-server/private-maps/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Example: Sending stack traces to your server</title>
</head>
<body>
<h1>Sending stack traces to your server</h1>
<p>All tests load code bundled from this file <code>/retrace/test/fixture/main.js</code></p>
<h2>Private source maps</h2>
<p>(configure retrace where exactly to get the source maps from)</p>
<ul>
<li><a href="bundle.private.min.html">Minified bundle with no public source map</a></li>
</ul>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>bundle.private.min.js</title>
<script src="bundle.private.min.js"></script>
</head>
<body>
...
</body>
</html>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions examples/stack-traces-to-server/private-maps/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var express = require('express');
var fs = require('fs');
var path = require('path');

var retrace = require('../../../');

retrace.resolve = function (url){
if(url && url.includes('bundle.private.min.js')){
return new Promise((resolve, reject) => {
fs.readFile(path.resolve(__dirname, 'bundle.private.min.js.map'), (err, data) => {
if(err)
reject(err);
else
resolve(JSON.parse(data));
});
});
}
return null;
};

console.log('resolving with private maps location');

var app = require('../server-common');
app.use(express.static(path.resolve(__dirname, 'public')));
app.get('/', function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/html'
});
fs.createReadStream(path.resolve(__dirname, 'index.html')).pipe(res);
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions examples/stack-traces-to-server/public-maps/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Example: Sending stack traces to your server</title>
</head>
<body>
<h1>Sending stack traces to your server</h1>
<p>All tests load code bundled from this file <code>/retrace/test/fixture/main.js</code></p>
<p>Pick one of the test HTML files below and see how the code there will throw an error, catch it, send to the server for remapping and will print the remapped trace.</p>
<h2>Having retrace to fetch the source maps itself</h2>
<p>(by default retrace downloads the sources and source maps via HTTP)</p>
<ul>
<li><a href="bundle.html">Bundle</a></li>
<li><a href="bundle.inline.html">Bundle with inline source map</a></li>
<li><a href="bundle.min.html">Minified bundle</a></li>
</ul>
</body>
</html>
12 changes: 12 additions & 0 deletions examples/stack-traces-to-server/public-maps/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var fs = require('fs');
var path = require('path');

console.log('resolving with public maps');

require('../server-common').get('/', function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/html'
});
fs.createReadStream(path.resolve(__dirname, 'index.html')).pipe(res);
});

34 changes: 34 additions & 0 deletions examples/stack-traces-to-server/server-common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

var express = require('express');
var http = require('http');
var fs = require('fs');
var path = require('path');

var retrace = require('../../');

/* Small express app that send sthe mapped stack trace back to the client. */

var app = express();
app.use(express.static(path.resolve(__dirname, '../../test/fixture')));
app.get('/retrace', function(req, res) {
// Read the stack from a query parameter
var stack = req.query.stack;
// ... pass it to retrace
retrace.map(stack).then(function(s) {
// ... and send back the re-mapped stack trace
res.send(s);
})
.catch(function(err) {
res.status(500).send(err);
})
.finally(function() {
res.end();
})
});

var server = http.createServer(app);
server.listen(8001);

console.log('server running. please check http://localhost:8001');

module.exports = app;
Loading

0 comments on commit 7c9242e

Please sign in to comment.