This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
70 lines (52 loc) · 1.76 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
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
if (process.env.NODE_ENV === 'production') {
require('@google/cloud-trace').start();
require('@google/cloud-debug');
}
var path = require('path');
var express = require('express');
var config = require('./config');
var logging = require('./lib/logging');
var https = require('https');
var fs = require('fs');
var app = express();
app.disable('etag');
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.set('trust proxy', true);
app.use(logging.requestLogger);
app.use('/reflector/list', require('./reflector/list'))
app.use('/reflector/test', require('./reflector/test'))
app.use('/reflector/upload', require('./reflector/upload'))
app.get('/', function (req, res) {
res.redirect('/reflector/list');
});
app.use(logging.errorLogger);
// Basic 404 handler
app.use(function (req, res) {
res.status(404).send('Not Found');
});
// Basic error handler
app.use(function (err, req, res, next) {
/* jshint unused:false */
res.status(500).send(err.response || 'Something broke!');
});
if (module === require.main) {
var server;
if (process.env.NODE_ENV !== 'production') {
var privateKey = fs.readFileSync('sslcert/server.key', 'utf8');
var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
server = https.createServer(credentials, app);
} else {
server = app;
}
var runningServer = server.listen(config.get('PORT'), function () {
var port = runningServer.address().port;
console.log('Reflector server listening on port %s', port);
});
}
module.exports = app;