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 express = require('express')
|
||||||
const eApp = express()
|
const eApp = express()
|
||||||
|
|
||||||
|
const frontendPath = 'frontend/'
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
const mainWindow = new BrowserWindow({
|
const mainWindow = new BrowserWindow({
|
||||||
@ -22,14 +24,16 @@ function createWindow() {
|
|||||||
mainWindow.setMenuBarVisibility(false)
|
mainWindow.setMenuBarVisibility(false)
|
||||||
|
|
||||||
// Start a local express server to serve static files
|
// Start a local express server to serve static files
|
||||||
// TODO: Handle things like /login not found
|
eApp.use(express.static(frontendPath))
|
||||||
eApp.use(express.static('frontend/'))
|
// 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', () => {
|
const server = eApp.listen(0, '127.0.0.1', () => {
|
||||||
console.log(`Server started on port ${server.address().port}`)
|
console.log(`Server started on port ${server.address().port}`)
|
||||||
mainWindow.loadURL(`http://127.0.0.1:${server.address().port}`)
|
mainWindow.loadURL(`http://127.0.0.1:${server.address().port}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// Open the DevTools.
|
// Open the DevTools.
|
||||||
// mainWindow.webContents.openDevTools()
|
// mainWindow.webContents.openDevTools()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user