Rewrite urls served by express and not static
continuous-integration/drone/push Build is passing Details

This commit is contained in:
kolaente 2020-10-17 18:36:08 +02:00
parent cb5fc63eb5
commit 14a3cf308b
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 7 additions and 3 deletions

10
main.js
View File

@ -2,6 +2,8 @@ const {app, BrowserWindow, shell} = require('electron')
const express = require('express')
const eApp = express()
const frontendPath = 'frontend/'
function createWindow() {
// Create the browser window.
const mainWindow = new BrowserWindow({
@ -22,14 +24,16 @@ function createWindow() {
mainWindow.setMenuBarVisibility(false)
// Start a local express server to serve static files
// TODO: Handle things like /login not found
eApp.use(express.static('frontend/'))
eApp.use(express.static(frontendPath))
// Handle urls set by the frontend
eApp.get('*', (request, response, next) => {
response.sendFile(`${__dirname}/${frontendPath}index.html`);
})
const server = eApp.listen(0, '127.0.0.1', () => {
console.log(`Server started on port ${server.address().port}`)
mainWindow.loadURL(`http://127.0.0.1:${server.address().port}`)
})
// Open the DevTools.
// mainWindow.webContents.openDevTools()
}