Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
93 lines (71 loc) · 2.41 KB
/
Copy pathindex.js
File metadata and controls
93 lines (71 loc) · 2.41 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
const express = require('express')
const http = require('http')
const RED = require('node-red');
const path = require('path')
const routes = require('./routes')
const { auth, log,permission } = require('./middleware')
const cookies = require('cookie-parser')
const userSettings = require('./user_settings')
const stackPush = require('./utils/pushParser')
const redFunction = require('./RedFunction')
const app = express()
app.stack = []
app.stackPush = stackPush
app.baseDir = __dirname
//static files
app.use('/static', express.static("public"))
// app.use('/vue', express.static("vue-html/dist/vue")) //old url , not use
app.use('/sa', express.static("admin/dist/sa")) //static-admin 未来的功能扩展-管理员端
// app.use('/sc', express.static("admin/dist/sc")) //static-client 未来的功能扩展-客户端
// view engine setup
app.engine('html', require('express-art-template'));
app.set('views', {
debug: true
});
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'art');
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.use(cookies())
app.use(auth)
// app.use(log)
app.use(permission)
// app.use('/main', express.static("vue-html/dist/index.html")) //old url,not use
app.use('/admin', express.static("admin/dist/index.html"))
// app.use('/client', express.static("client/dist/index.html"))
routes(app)
const server = http.createServer(app)
//node-red user dir
const nodePath = path.join(__dirname, 'red_dir')
let settings = {
httpAdminRoot: "/red",
httpNodeRoot: "/api",
userDir: nodePath,
ui: { path: '/ui' },
functionGlobalContext: redFunction, // enables global context
credentialSecret: "fdsfrrrwtta"
};
app.stackPush('all', '/red')
app.stackPush('all', '/api')
app.stackPush('all', '/admin')
// Initialise the runtime with a server and settings
RED.init(server, settings);
// Serve the editor UI from /red
app.use(settings.httpAdminRoot, RED.httpAdmin);
// Serve the http nodes UI from /api
app.use(settings.httpNodeRoot, RED.httpNode);
app.use(function (err, req, res, next) {
if (err) {
res.send('sorry,error coming...')
}
})
app.all('*', async function (req, res) {
await setTimeout(() => {
res.render('404.html', {})
}, 500);
})
server.listen(userSettings.port, function () {
console.log(`--------------------------server is running on port:${userSettings.port}--------------------------------`)
});
// Start the runtime
RED.start();