-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
119 lines (91 loc) · 2.62 KB
/
app.js
File metadata and controls
119 lines (91 loc) · 2.62 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* Electron Dependencies
*/
var appAtomShell = require('app'); // Module to control application life.
var BrowserWindow = require('browser-window'); // Module to create native browser window.
/**
* Webapp Dependencies
*/
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var Faker = require('faker');
var config = require('./config.json');
var app = express();
app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/', express.static(path.join(__dirname, 'public')));
/**
* Dummy Data setup
*/
var userData = [];
for (i = 0; i < 20; i++) {
userData.push({
name: Faker.name.firstName() + ' ' + Faker.name.lastName(),
id: Faker.random.uuid(),
philosophy: Faker.hacker.phrase()
});
}
var fakeData = [{
name: 'Gregory',
age: 26,
gender: 'male',
id: 1
}, {
name: 'Mini',
age: 24,
gender: 'female',
id: 2
}];
/**
* Dummy Routes
*/
app.get('/users', function(req, res) {
res.json(fakeData)
});
app.post('/users/new', function(req, res) {
fakeData.push(req.body);
res.json(fakeData);
});
/**
* Application Port setup
*/
app.listen(config.port, function() {
console.info('app server is listening on port 7777');
});
/**
* Electron Config
*/
// Report crashes to our server.
require('crash-reporter').start();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;
// Quit when all windows are closed.
appAtomShell.on('window-all-closed', function() {
if (process.platform != 'darwin')
appAtomShell.quit();
});
// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
appAtomShell.on('ready', function() {
console.log('READY is called');
// Create the browser window.
mainWindow = new BrowserWindow({width: 1400, height: 900, fullScreen: true, 'node-integration': false});
// and load the index.html of the app.
mainWindow.loadUrl('http://localhost:' + config.port);
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});