Skip to content

Commit

Permalink
Fix cache file read error
Browse files Browse the repository at this point in the history
  • Loading branch information
Raathigesh committed Jun 6, 2016
1 parent e44feb4 commit 8e624f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "atmo",
"version": "0.4.0",
"version": "0.4.1",
"description": "Mocking Http, Socket, Graphql Endpoints made with ease through UI",
"main": "src/server/index.js",
"scripts": {
Expand All @@ -23,6 +23,7 @@
"chalk": "^1.1.3",
"express": "^4.13.4",
"express-remove-route": "^0.1.1",
"file-exists": "^1.0.0",
"freeport": "^1.0.5",
"graphql": "^0.5.0",
"socket.io": "^1.4.5",
Expand Down Expand Up @@ -56,7 +57,7 @@
"webpack-dev-server": "^1.14.1"
},
"bin": {
"atmo": "src/server/index.js"
"atmo": "src/server/index.js"
},
"babel": {
"presets": [
Expand Down
11 changes: 8 additions & 3 deletions src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var freeport = require('freeport');
var argv = require('yargs').argv;
var fs = require('fs');
var path = require('path');
var fileExists = require('file-exists');
var cacheFilePath = path.join(__dirname, '../../cache/spec.json');

app.use(express.static(__dirname + '../../../dist'));

Expand All @@ -32,9 +34,12 @@ freeport(function(err, port) {
api = apiServer.createApiServer(apiServerPort, argv.static);
});


io.on('connection', function(socket) {
var cacheSpec = JSON.parse(fs.readFileSync(path.join(process.cwd(), '/cache/spec.json')));
var cacheSpec = {};
if (fileExists(cacheFilePath)) {
cacheSpec = JSON.parse(fs.readFileSync(cacheFilePath));
}

socket.emit('onStart', {
port: apiServerPort,
spec: cacheSpec
Expand All @@ -47,6 +52,6 @@ io.on('connection', function(socket) {
});

socket.on('save', function (spec) {
fs.writeFileSync(path.join(process.cwd(), '/cache/spec.json'), JSON.stringify(spec));
fs.writeFileSync(cacheFilePath, JSON.stringify(spec));
});
});

0 comments on commit 8e624f8

Please sign in to comment.