Rewrite urls served by express and not static
This commit is contained in:
parent
cb5fc63eb5
commit
14a3cf308b
10
main.js
10
main.js
@ -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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user