-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
87 lines (65 loc) · 1.66 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
77
78
79
80
81
82
83
84
85
86
"use strict";
require('dotenv').config();
const express = require('express')
const cors = require('cors')
const app = express()
const port = process.env.PORT || 3000;
const formidable = require('formidable');
const ordinal = require('./ordinal');
app.use(cors());
app.use(express.json()) // for parsing application/json
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
// === FILE UPLOAD
app.all('/fileupload', (req, res) => {
let form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
if (err) {
let error = err.message || err ;
res.status(500).json({
success: false,
message: error
});
} else {
ordinal.upload(files).then(result => {
res.json({
success: true,
message: 'Uploaded',
rdata: result
});
}).catch(err => {
let error = err.message || err ;
res.status(500).json({
success: false,
message: error
});
})
}
});
});
// === COMMANDS
app.all('/', (req, res) => {
if (req.body && Array.isArray(req.body)) {
ordinal.rpc(req.body).then(data => {
res.json({
success: true,
message: 'Command successful',
rdata: data
});
}).catch(err => {
let error =err.message || err ;
res.status(500).json({
success: false,
message: error
});
});
} else {
res.status(500).json({
success: false,
message: 'Invalid request. Missing some parameters?'
});
}
});
// === END
app.listen(port, () => {
console.log(`Listening on port ${port}`)
});