forked from shruthipinnamwar/shruthipinnamwar.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local.js
51 lines (49 loc) · 1.63 KB
/
local.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
var path = require('path'), express = require('express');
var qs = require('querystring');
var app = express();
app.use('/ui5', express.static(path.join(__dirname, 'webapp')));
// app.use('/wt', express.static(path.join(__dirname, 'walkthrough')));
app.use('/mindmap', express.static(path.join(__dirname, 'mindmap')));
app.use('/module', express.static(path.join(__dirname, 'module')));
app.get('/', function(req, res){
console.log("method in get/: " + req.method);
var qs = require('querystring');
res.send("Hello World");
});
app.post("/", function(req, res){
var body = '';
const regex = /!\[(.*?)\]\((.*?)\)/g;
var m;
var printResult = ( array ) => {
var aResult = [];
var url = array[2];
var splited = url.split(".");
var oResult = {
"localFile": array[1] + "." + splited[splited.length-1],
"fileUrl": url
};
aResult.push(oResult);
return aResult;
};
req.on('data', function (data) {
body += data;
if (body.length > 1e6)
request.connection.destroy();
});
req.on('end', function () {
var post = qs.parse(body);
var aResult = [];
// res.send("your request is: " + post.markdown_source);
while ((m = regex.exec(post.markdown_source)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
aResult = aResult.concat(printResult(m));
}
console.log(aResult);
res.json(aResult);
});
});
app.listen(process.env.PORT || 3000, function(){
console.log("Example app listens on port 3000.");
});