UNPKG

1.73 kBJavaScriptView Raw
1/*
2 * This code was created for Printr B.V. It is open source under the formideos-interface package.
3 * Copyright (c) 2015, All rights reserved, http://printr.nl
4 */
5
6var express = require('express');
7var app = express();
8
9module.exports = {
10
11 server: null,
12 port: 8080,
13
14 init: function() {
15 // this.startInterface()
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 // stop server before disposing module
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 // app (component views)
53 app.get('/app/*', function(req, res) {
54 return res.sendfile(req.params[0], {root: __dirname + '/app'});
55 });
56
57 // basic app environment info
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 // public assets
69 app.get('/public/*', function(req, res) {
70 return res.sendfile(req.params[0], {root: __dirname + '/public'});
71 });
72
73 // angular app
74 app.get('/*', function(req, res) {
75 return res.sendfile('index.html', {root: __dirname});
76 });
77 }
78}