ctucx.git: trainsearch

web based trip-planner, fork of https://cyberchaos.dev/yuka/trainsearch

commit fe008383474dda50264b33b6ea42ae26ce20973e
parent 6808e42445df6ad9a3cabd9762f3b853d865d99b
Author: Katja (ctucx) <git@ctu.cx>
Date: Mon, 27 Jan 2025 13:31:43 +0100

general: activate sw only when not running in dev-server
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/dataStorage.js b/src/dataStorage.js
@@ -1,9 +1,8 @@
 import { openDB, deleteDB } from 'idb';
 
-export const devMode = false;
 export let db;
 
-const dbName = devMode ? 'trainsearch_dev' : 'trainsearch';
+const dbName = !isDevServer ? 'trainsearch' : 'trainsearch_dev';
 
 class IDBStorage {
 	constructor(idb) {
diff --git a/src/main.js b/src/main.js
@@ -30,7 +30,9 @@ import { departuresView } from './departuresView.js';
 
 	if (!window.location.hash.length) go('/');
 	start();
+}) ();
 
+if (!isDevServer) {
 	window.addEventListener('load', () => {
 		navigator.serviceWorker.register('/service-worker.js').then(registration => {
 			console.log('SW registered: ', registration);

@@ -38,4 +40,4 @@ import { departuresView } from './departuresView.js';
 			console.log('SW registration failed: ', registrationError);
 		});
 	});
-}) ();
+}
diff --git a/webpack.config.js b/webpack.config.js
@@ -50,6 +50,7 @@ module.exports = {
     }),
     new DefinePlugin({
       "process.env": "{}",
+      "isDevServer": process.env.WEBPACK_SERVE,
     }),
     new ProvidePlugin({
       Buffer: ['buffer', 'Buffer'],