Created
November 28, 2023 19:29
-
-
Save peace899/140f3850c018931a4bc7419dcc3eced6 to your computer and use it in GitHub Desktop.
Simple webview/express js app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Requires: https://github.com/suchipi/webview-node and expressjs | |
var webview = require("webview"); | |
var express = require("express"); | |
const path = require('path') | |
const app = express(); | |
app.use('/static', express.static(path.join(__dirname, 'public'))) | |
app.get('/', (req, res) => { | |
res.sendFile(path.join(__dirname, '/public/index.html')) | |
}) | |
const server = app.listen(0, () => { | |
console.log('Listening on port:', server.address().port); | |
setTimeout(startGui, 1000, server.address().port); | |
}); | |
function startGui(port) { | |
webview.spawn({ | |
title:"My App", | |
url: `http://localhost:${port}`, | |
width: 800, | |
height: 600, | |
dir: "./public", | |
cwd: process.cwd(), | |
}).on('close', function() { | |
console.log('close'); | |
process.exit() | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment