Skip to content

Instantly share code, notes, and snippets.

@peace899
Created November 28, 2023 19:29
Show Gist options
  • Save peace899/140f3850c018931a4bc7419dcc3eced6 to your computer and use it in GitHub Desktop.
Save peace899/140f3850c018931a4bc7419dcc3eced6 to your computer and use it in GitHub Desktop.
Simple webview/express js app
//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