Fixed multiple window issue

This commit is contained in:
Benoit Schweblin 2017-09-29 19:43:26 +01:00
parent f8f3a87559
commit 6bbe22aaa2
6 changed files with 49 additions and 43 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
.vscode
stackedit_v4

View File

@ -7,7 +7,7 @@ var path = require('path');
var express = require('express');
var app = express();
require('./server')(app);
require('./server')(app, process.env.SERVE_V4);
var port = parseInt(process.env.PORT || 8080, 10);
if(port === 443) {

View File

@ -39,7 +39,6 @@
"raw-loader": "^0.5.1",
"request": "^2.82.0",
"serve-static": "^1.12.6",
"stackedit": "^4.3.17",
"vue": "^2.3.3",
"vuex": "^2.3.1"
},

View File

@ -2,15 +2,18 @@ var compression = require('compression');
var serveStatic = require('serve-static');
var path = require('path');
module.exports = function (app) {
module.exports = function (app, serveV4) {
// Use gzip compression
if (process.env.NODE_ENV === 'production') {
// Force HTTPS on stackedit.io
app.all('*', function(req, res, next) {
// Force HTTPS on stackedit.io
if (req.headers.host === 'stackedit.io' && !req.secure && req.headers['x-forwarded-proto'] !== 'https') {
return res.redirect('https://stackedit.io' + req.url);
}
/\.(eot|ttf|woff|svg)$/.test(req.url) && res.header('Access-Control-Allow-Origin', '*');
// Enable CORS for fonts
if (/\.(eot|ttf|woff|svg)$/.test(req.url)) {
res.header('Access-Control-Allow-Origin', '*');
}
next();
});
@ -18,10 +21,12 @@ module.exports = function (app) {
}
app.get('/oauth2/githubToken', require('./github').githubToken);
app.post('/pdfExport', require('stackedit/app/pdf').export);
app.post('/sshPublish', require('stackedit/app/ssh').publish);
app.post('/picasaImportImg', require('stackedit/app/picasa').importImg);
app.get('/downloadImport', require('stackedit/app/download').importPublic);
if (serveV4) {
app.post('/pdfExport', require('../stackedit_v4/app/pdf').export);
app.post('/sshPublish', require('../stackedit_v4/app/ssh').publish);
app.post('/picasaImportImg', require('../stackedit_v4/app/picasa').importImg);
app.get('/downloadImport', require('../stackedit_v4/app/download').importPublic);
}
// Serve callback.html in /app
app.get('/oauth2/callback', function(req, res) {
@ -30,29 +35,35 @@ module.exports = function (app) {
// Serve static resources
if (process.env.NODE_ENV === 'production') {
if (serveV4) {
// Serve landing.html in /
app.get('/', function(req, res) {
res.sendFile(require.resolve('stackedit/views/landing.html'));
res.sendFile(require.resolve('../stackedit_v4/views/landing.html'));
});
// Serve editor.html in /viewer
app.get('/editor', function(req, res) {
res.sendFile(require.resolve('stackedit/views/editor.html'));
res.sendFile(require.resolve('../stackedit_v4/views/editor.html'));
});
// Serve viewer.html in /viewer
app.get('/viewer', function(req, res) {
res.sendFile(require.resolve('stackedit/views/viewer.html'));
res.sendFile(require.resolve('../stackedit_v4/views/viewer.html'));
});
}
// Serve index.html in /app
app.get('/app', function(req, res) {
res.sendFile(path.join(__dirname, '../dist/index.html'));
});
app.use(serveStatic(path.join(__dirname, '../dist'))); // v5
app.use(serveStatic(path.dirname(require.resolve('stackedit/public/cache.manifest')))); // v4
app.use(serveStatic(path.join(__dirname, '../dist')));
if (serveV4) {
app.use(serveStatic(path.dirname(require.resolve('../stackedit_v4/public/cache.manifest'))));
// Error 404
app.use(function(req, res) {
res.status(404).sendFile(require.resolve('stackedit/views/error_404.html'));
res.status(404).sendFile(require.resolve('../stackedit_v4/views/error_404.html'));
});
}
}
};

View File

@ -98,15 +98,14 @@ const localDbSvc = {
connection: new Connection(),
/**
* Return a promise that is resolved once the synchronization between the store and the localDb
* is finished. Effectively, open a transaction, then read and apply all changes from the DB
* since the previous transaction, then write all the changes from the store.
* Return a promise that will be resolved once the synchronization between the store and the
* localDb will be finished. Effectively, open a transaction, then read and apply all changes
* from the DB since the previous transaction, then write all the changes from the store.
*/
sync() {
return new Promise((resolve, reject) => {
const storeItemMap = { ...store.getters.allItemMap };
this.connection.createTx((tx) => {
this.readAll(storeItemMap, tx, () => {
this.readAll(tx, (storeItemMap) => {
this.writeAll(storeItemMap, tx);
if (!store.state.ready) {
store.commit('setReady');
@ -120,7 +119,7 @@ const localDbSvc = {
/**
* Read and apply all changes from the DB since previous transaction.
*/
readAll(storeItemMap, tx, cb) {
readAll(tx, cb) {
let lastTx = this.lastTx;
const dbStore = tx.objectStore(dbStoreName);
const index = dbStore.index('tx');
@ -142,6 +141,7 @@ const localDbSvc = {
changes.push(item);
cursor.continue();
} else {
const storeItemMap = { ...store.getters.allItemMap };
changes.forEach((item) => {
this.readDbItem(item, storeItemMap);
// If item is an old delete marker, remove it from the DB
@ -150,7 +150,7 @@ const localDbSvc = {
}
});
this.lastTx = lastTx;
cb();
cb(storeItemMap);
}
};
},

View File

@ -29,17 +29,12 @@ module.mutations.setItem = (state, value) => {
: value.data;
const item = {
...emptyItem,
...value,
data,
hash: Date.now(),
};
if (item.id === 'settings' || item.id === 'templates') {
// Use a real hash for synced types
item.hash = utils.hash(utils.serializeObject({
...item,
hash: undefined,
}));
}
Vue.set(state.itemMap, item.id, item);
};