Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/externalize json #36

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
27 changes: 27 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"rules": {
"no-console": 0,
"indent": 4,
"quotes": [
2,
"single"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
]
},
"env": {
"es6": true,
"node": true
},
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
},
"extends": "eslint:recommended"
}
14 changes: 0 additions & 14 deletions .eslintrc.js

This file was deleted.

9 changes: 3 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the terms of the MIT license. Please see LICENSE file in the project root for terms.

var Promise = require('bluebird');
var messageHash = require('incoming-message-hash');
var assert = require('assert');
var mkdirp = require('mkdirp');
var path = require('path');
Expand All @@ -21,7 +20,7 @@ var debug = require('debug')('yakbak:server');
* @returns {Function}
*/

module.exports = function (host, opts) {
module.exports = function(host, opts) {
assert(opts.dirname, 'You must provide opts.dirname');

return function (req, res) {
Expand Down Expand Up @@ -52,7 +51,6 @@ module.exports = function (host, opts) {
}).catch(RecordingDisabledError, function (err) {
/* eslint-disable no-console */
console.log('An HTTP request has been made that yakbak does not know how to handle');
console.log(curl.request(req));
/* eslint-enable no-console */
res.statusCode = err.status;
res.end(err.message);
Expand All @@ -68,9 +66,8 @@ module.exports = function (host, opts) {
*/

function tapename(req, body) {
var hash = opts.hash || messageHash.sync;

return hash(req, Buffer.concat(body)) + '.js';
let path = req.path.replace(/\//g, '_');
return path + '.js'; //look for json file
}

};
Expand Down
15 changes: 13 additions & 2 deletions lib/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var path = require('path');
var ejs = require('ejs');
var fs = require('fs');
var debug = require('debug')('yakbak:record');

/**
* Read and pre-compile the tape template.
* @type {Function}
Expand All @@ -26,9 +25,21 @@ var render = ejs.compile(fs.readFileSync(path.resolve(__dirname, '../src/tape.ej
* @returns {Promise.<String>}
*/

function writeStreamToFile(file_name, stream){

let file = fs.createWriteStream(file_name);
stream.forEach((data) => {file.write(data.toString(), 'utf8')})
file.end();

}


module.exports = function (req, res, filename) {
return buffer(res).then(function (body) {
return render({ req: req, res: res, body: body });
let data_file = filename.replace(/\.js$/, '.json');
//fs.writeFileSync(data_file, body.toString(), 'utf8');
writeStreamToFile(data_file, body);
return render({fs: fs, data_file: data_file, json_data: body.toString(), req: req, res: res, body: body });
}).then(function (data) {
return write(filename, data);
}).then(function () {
Expand Down
Loading