Skip to content

Instantly share code, notes, and snippets.

@coenraadhuman
Last active August 22, 2019 13:46
Show Gist options
  • Save coenraadhuman/1f219c7e5c1de60dd3202bd6ffbc91c4 to your computer and use it in GitHub Desktop.
Save coenraadhuman/1f219c7e5c1de60dd3202bd6ffbc91c4 to your computer and use it in GitHub Desktop.
Using Angular and Firebase Project with Electron App Workaround
require('./server');
const { app, BrowserWindow } = require('electron')
let win;
function createWindow () {
// Create the browser window.
win = new BrowserWindow({
width: 1200,
height: 720,
backgroundColor: '#ffffff',
icon: `http://localhost:3007/assets/favicon.ico`
});
// clear web contents for testing
// win.webContents.session.clearCache(function(){
// console.log('Cache Cleared!')
// });
// win.webContents.session.clearStorageData(function(){
// console.log('Storage Cleared!');
// });
win.loadURL(`http://localhost:3007`)
// uncomment below to open the DevTools.
// win.webContents.openDevTools()
// Event when the window is closed.
win.on('closed', function () {
win = null
})
}
// Create window on electron intialization
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On macOS specific close process
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
// macOS specific close process
if (win === null) {
createWindow()
}
});
var express = require('express');
var http = require('http');
var path = require('path');
var appServer = express();
appServer.use(express.static(path.join(__dirname, 'dist','penguin-messenger'))); // this determines the destination of served files
appServer.get('*', (req, res) => {
res.sendFile(__dirname + 'index.html');
});
http.createServer(appServer).listen(3007, function() {
console.log('Express server listening on port');
});