-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (60 loc) · 2.34 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
/**
* Created by danielabrao on 1/31/17.
*/
(function () {
"use strict";
require("dotenv").config({"silent": true});
var express = require("express"),
app = express(),
path = require("path"),
cfenv = require("cfenv"),
appEnv = cfenv.getAppEnv(),
fs = require("fs"),
engines = require('consolidate'),
ejs = require("ejs"),
request = require("request"),
bodyParser = require("body-parser"),
compress = require("compression"),
server = require("http").createServer(app),
FileHandler = require("./server/factory/fileHandler")(),
apiDocs = require("./server/model/swagger/api.script"),
sttFactory = require("./server/factory/audioConverter")(),
ttsFactory = require("./server/factory/textConverter")(),
wcsFactory = require("./server/factory/conversation")(),
multer = require("multer"),
upload = multer({
fileFilter: function (req, file, cb) {
console.log(file);
try {
var splittedName = file.originalname.split(".");
file.dataType = splittedName[splittedName.length - 1];
} catch(e) {
console.log(e);
}
return cb(null, true);
}
}),
morgan = require("morgan");
app.use(express.static(path.join(__dirname, "./client/")));
app.use(compress());
app.use(morgan("dev"));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({limit: "50mb"}));
app.engine("html", engines.ejs);
app.set("views", __dirname + "/client/");
app.set("view engine", "html");
app.all("/*", function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE, OPTIONS");
res.header("Access-Control-Allow-Headers", "X-Requested-With, Content-type, Accept, X-Access-Token, X-Key");
if (req.method === "OPTIONS") {
res.status(200).end();
} else {
next();
}
});
require("./server/routes/index.script")(app, upload, ttsFactory, sttFactory, wcsFactory, FileHandler, fs, apiDocs);
server.listen(appEnv.port, appEnv.bind, function () {
console.log(appEnv.url);
});
}());