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-debug.log*
yarn-error.log* yarn-error.log*
.vscode .vscode
stackedit_v4

View File

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

View File

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

View File

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

View File

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

View File

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