-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.js
57 lines (42 loc) · 1.41 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
'use strict'
const express = require('express')
require('dotenv').config()
const minify = require('express-minify')
const gaConfig = require('./config/ga_config.js');
const create = require('./api/controllers/create.js')
const send = require('./api/controllers/send.js')
const javascript = require('./api/controllers/javascript.js')
const app = express()
app.set('view engine', 'ejs')
app.use(minify())
app.options('*', function (req, res) {
res
.status(200)
.header('Access-Control-Allow-Headers', 'Content-Type')
.header('Access-Control-Allow-Origin', '*')
.send()
})
let router = express.Router()
app.use(process.env.BASE_PATH, router)
router.route('/swagger')
.get(function (req, res) {
res
.status(200)
.header('Access-Control-Allow-Headers', 'Content-Type')
.header('Access-Control-Allow-Origin', '*')
.sendFile(__dirname + '/swagger/v0.1.json')
})
router.route('/javascript/gaproxy.js')
.get(javascript.getJavascript)
router.route('/create')
.get(create.create)
router.route('/send/pageview')
.get(send.sendPageView)
router.route('/send/event')
.get(send.sendEvent)
if (!process.env.AWS_LAMBDA_FUNCTION_NAME) {
gaConfig.logger.info('Using ' + process.env.BASE_PATH + ' for base path.')
gaConfig.logger.info('Server listing on port ' + (process.env.PORT || 3001) + ' at ' + process.env.BASE_PATH + '.')
app.listen(process.env.PORT || 3001)
}
module.exports = app