-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
76 lines (63 loc) · 2.27 KB
/
app.js
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
//my components
const config = require('./src/_config.js');
const feed = require('./src/feed.js');
const storage = require('./src/storage.js');
const sysInfo = require('./src/www/sys-info');
//Express
const express = require('express');
const app = express();
//Lodash
const _ = require('lodash-node');;
//json output
app.get('/json', function (req, res) {
storage.loadItems(function (items) {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Headers", "X-Requested-With");
res.end(JSON.stringify(items));
}, req.query.count, req.query.filter);
});
//js snippet code
app.get('/snippet.js', function (req, res) {
res.sendfile(__dirname + '/snippet.js');
});
//js snippet code
app.get('/info', function (req, res) {
res.setHeader('Content-Type', 'application/json');
res.setHeader('Cache-Control', 'no-cache, no-store');
res.end(JSON.stringify({
gen: sysInfo.gen(),
poll: sysInfo.poll()
}));
});
//status page
app.get('/', function (req, res) {
//Webpages
const www_page = require('./src/www/_page.js');
const www_config = require('./src/www/config.js');
var active = req.query.active || "";
var content = "";// _.template(www_nav.template)({ active: active })
// if (active === "config") {
content += _.template(www_config.template)({ active: active, words: req.query.words || "", NODE_ENV: process.env.NODE_ENV })
// } else if (active === "items") {
// content += _.template(www_items.template)({ active: active })
// } else {
// content += _.template(www_state.template)({ active: active })
// }
res.send(_.template(www_page.template)({ content: content }));
});
//404
app.get('*', function (req, res) {
res.send(404).send('404 - not found');
});
//
// konfigurace weboveho serveru
//
var addr = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
var port = process.env.OPENSHIFT_NODEJS_PORT || 8000;
//
// Start weboveho serveru
//
app.listen(port, addr, function () {
console.log('The app listening at http://%s:%s', addr, port, `Application worker ${process.pid} started...`);
});