-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
108 lines (72 loc) · 2.49 KB
/
index.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
______ _ _ _
\ ___|_) | | (_)
\ \ _ __ _ _ __ ___ __ _| |_ _ ___ _ __
> > | |/ _` | '_ ` _ \ / _` | __| |/ _ \| '_ \
/ /__| | (_| | | | | | | (_| | |_| | (_) | | | |
/_____)_|\__, |_| |_| |_|\__,_|\__|_|\___/|_| |_|
__/ |
|___/
*/
//*******************************************************************
'use strict';
//*******************************************************************
// required modules
require('dotenv').config();
var express = require('express');
var helmet = require('helmet');
var cors = require('cors');
var path = require('path');
var fsr = require('file-stream-rotator');
var mkdirp = require('mkdirp');
var morgan = require('morgan');
var mathjax = require("mathjax-node/lib/mj-single.js");
var sigma = require('./controllers/sigma.js');
//*******************************************************************
// mathjax
mathjax.config({
MathJax: {
// traditional MathJax configuration
}
});
mathjax.start();
//*******************************************************************
// environment variables
var PORT = process.env.PORT;
//*******************************************************************
//express
var app = express();
app.use(cors());
app.use(helmet());
// **********************************************************
// log
var logDirectory = path.join(__dirname,'/log');
mkdirp(logDirectory);
var accessLogStream = fsr.getStream({
filename: logDirectory + '/fs-epermit-api-%DATE%.log',
frequency: 'daily',
verbose: false
});
app.use(morgan('combined', {stream: accessLogStream}));
//*******************************************************************
// public
app.use(express.static('public'));
//*******************************************************************
// routes
app.get('/math(.:ext)', function(req,res){
sigma.process(req, res, mathjax);
});
app.get('/math', function(req,res){
sigma.process(req, res, mathjax);
});
//*******************************************************************
// listen
var server = app.listen(PORT, function () {
var host = server.address().address;
var port = server.address().port;
console.log('\n listening at http://%s:%s', host, port);
});
//*******************************************************************
// exports
module.exports = app;
//*******************************************************************