-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
86 lines (61 loc) · 1.73 KB
/
main.js
File metadata and controls
86 lines (61 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Created by lgabster on 2016.05.31..
*/
const {app, remote, BrowserWindow, crashReporter} = require('electron')
const express = require('express')
const expressApp = express()
const path = require('path')
const fs = require('fs')
const http = require('http')
const port = process.env.PORT || '8000'
const appUrl = 'http://127.0.0.1:' + port
global.appUrl = appUrl
const middleware = require('./middleware')
let mainWindow
let server
var ctrlPath = path.join(__dirname, 'controllers')
var readControllers = (dir) => {
console.log('Scanning for controllers ' + dir)
fs.readdirSync(dir).forEach((file) => {
var fullPath = dir + '/' + file
if (file.substr(-3) === '.js') {
console.log('Loading '+file)
var route = require(fullPath)
if (route.controller) {
route.controller(expressApp)
}
} else if(fs.lstatSync(fullPath).isDirectory()) {
readControllers(fullPath)
}
})
}
app.on('ready', () => {
middleware(expressApp)
expressApp.set('port', port)
readControllers(ctrlPath)
server = http.createServer(expressApp)
server.listen(port)
server.on('error', (error) => {
console.error(error)
process.exit(1)
})
mainWindow = new BrowserWindow({
width: 1800,
height: 800,
//frame: false,
//transparent: true
})
server.on('listening', () => {
mainWindow.loadURL(appUrl)
mainWindow.webContents.openDevTools()
})
mainWindow.on('closed', () => {
mainWindow = null
server.close()
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})