running own server to permit oauth workflow
This commit is contained in:
parent
4415a9d6be
commit
4274fce7f8
49
main.js
49
main.js
@ -1,6 +1,8 @@
|
|||||||
const {app, BrowserWindow, shell} = require('electron')
|
const { app, server, BrowserWindow, shell } = require('electron');
|
||||||
const path = require('path')
|
const path = require('path');
|
||||||
const url = require('url')
|
const url = require('url');
|
||||||
|
const http = require('http');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// Keep a global reference of the window object, if you don't, the window will
|
||||||
// be closed automatically when the JavaScript object is garbage collected.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
@ -9,7 +11,12 @@ const url = require('url')
|
|||||||
function createWindow() {
|
function createWindow() {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
win = new BrowserWindow({ width: 395, height: 800, title: "Sengi", backgroundColor: '#FFF' });
|
win = new BrowserWindow({ width: 395, height: 800, title: "Sengi", backgroundColor: '#FFF' });
|
||||||
win.loadURL("http://localhost:4200");
|
|
||||||
|
|
||||||
|
var server = http.createServer(requestHandler).listen(9527);
|
||||||
|
|
||||||
|
// win.loadURL("http://localhost:4200");
|
||||||
|
win.loadURL('http://localhost:9527');
|
||||||
win.setMenu(null);
|
win.setMenu(null);
|
||||||
|
|
||||||
// and load the index.html of the app.
|
// and load the index.html of the app.
|
||||||
@ -35,7 +42,41 @@ const url = require('url')
|
|||||||
// when you should delete the corresponding element.
|
// when you should delete the corresponding element.
|
||||||
win = null
|
win = null
|
||||||
})
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function requestHandler(req, res) {
|
||||||
|
var file = req.url == '/' ? '/index.html' : req.url,
|
||||||
|
root = __dirname + '/dist',
|
||||||
|
page404 = root + '/404.html';
|
||||||
|
|
||||||
|
if (file.includes('register')) file = '/index.html';
|
||||||
|
|
||||||
|
getFile((root + file), res, page404);
|
||||||
|
};
|
||||||
|
|
||||||
|
function getFile(filePath, res, page404) {
|
||||||
|
fs.exists(filePath, function (exists) {
|
||||||
|
if (exists) {
|
||||||
|
fs.readFile(filePath, function (err, contents) {
|
||||||
|
if (!err) {
|
||||||
|
res.end(contents);
|
||||||
|
} else {
|
||||||
|
console.dir(err);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fs.readFile(page404, function (err, contents) {
|
||||||
|
if (!err) {
|
||||||
|
res.writeHead(404, { 'Content-Type': 'text/html' });
|
||||||
|
res.end(contents);
|
||||||
|
} else {
|
||||||
|
console.dir(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user