1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var express = require('express');
|
7 | var app = express();
|
8 |
|
9 | module.exports = {
|
10 |
|
11 | server: null,
|
12 | port: 8080,
|
13 |
|
14 | init: function() {
|
15 |
|
16 | this.port = FormideOS.settings.get('formide-client-interface', 'port');
|
17 | if(FormideOS.settings.get('formide-client-interface', 'auto') == true) {
|
18 | this.startInterface()
|
19 | }
|
20 | },
|
21 |
|
22 | dispose: function() {
|
23 |
|
24 | this.server.close();
|
25 | },
|
26 |
|
27 | exposeSettings: function() {
|
28 | return [
|
29 | {
|
30 | name: "auto",
|
31 | type: "checkbox",
|
32 | label: "Start interface automatically",
|
33 | required: true,
|
34 | default: true
|
35 | },
|
36 | {
|
37 | name: "port",
|
38 | type: "text",
|
39 | label: "Port",
|
40 | required: true,
|
41 | default: 8080
|
42 | }
|
43 | ];
|
44 | },
|
45 |
|
46 | startInterface: function() {
|
47 |
|
48 | this.server = require('http').Server(app);
|
49 | this.server.listen(this.port);
|
50 | FormideOS.log.debug('Interface started on port ' + this.port);
|
51 |
|
52 |
|
53 | app.get('/app/*', function(req, res) {
|
54 | return res.sendfile(req.params[0], {root: __dirname + '/app'});
|
55 | });
|
56 |
|
57 |
|
58 | app.get('/api/env', function(req, res) {
|
59 | var pkg = require("./package.json");
|
60 | return res.json({
|
61 | environment: FormideOS.config.environment,
|
62 | name: pkg.name,
|
63 | version: pkg.version,
|
64 | location: "local"
|
65 | });
|
66 | });
|
67 |
|
68 |
|
69 | app.get('/public/*', function(req, res) {
|
70 | return res.sendfile(req.params[0], {root: __dirname + '/public'});
|
71 | });
|
72 |
|
73 |
|
74 | app.get('/*', function(req, res) {
|
75 | return res.sendfile('index.html', {root: __dirname});
|
76 | });
|
77 | }
|
78 | }
|