-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
82 lines (70 loc) · 2.46 KB
/
server.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
const express = require('express')
const favicon = require('serve-favicon')
const path = require('path')
const bodyParser = require('body-parser')
const compression = require('compression')
const Raven = require('raven')
const AV = require('leanengine')
const config = require('./config')
Raven.config(config.sentryDSN).install()
const app = express()
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
app.use(compression())
app.use(Raven.requestHandler())
// 加载云引擎中间件
app.use(AV.express())
app.enable('trust proxy')
app.use(AV.Cloud.HttpsRedirect())
app.use(express.static(path.join(__dirname, 'public')))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(require('./api'))
const orgName = require('./api/oauth').orgName
const getIndexPage = () => {
return `
<!doctype html public "storage">
<html>
<meta charset=utf-8/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>${config.siteName}</title>
<link rel="stylesheet" href="/css/highlight.default.min.css">
<link rel="stylesheet" href="/css/leancloud-base.css">
<link rel="stylesheet" href="/css/react-datepicker.css">
<link rel="stylesheet" href="/index.css">
<link rel="stylesheet" href="${process.env.WEBPACK_DEV_SERVER || ''}/app.css">
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<div id=app></div>
<script>
LEANCLOUD_APP_ID = '${process.env.LEANCLOUD_APP_ID}'
LEANCLOUD_APP_KEY = '${process.env.LEANCLOUD_APP_KEY}'
LEANCLOUD_APP_ENV = '${process.env.LEANCLOUD_APP_ENV}'
LEAN_CLI_HAVE_STAGING = '${process.env.LEAN_CLI_HAVE_STAGING}'
SENTRY_DSN_PUBLIC = '${config.sentryDSNPublic || ''}'
LEANCLOUD_SERVER_URL = '${process.env.LEANCLOUD_SERVER_URL}'
ORG_NAME = '${orgName}'
SITE_NAME = '${config.siteName}'
USE_OAUTH = 'false'
</script>
<script src='${process.env.WEBPACK_DEV_SERVER || ''}/bundle.js'></script>
<script>
window.addEventListener('load', function () {
if (window.Notification && Notification.permission !== "granted") {
Notification.requestPermission(function (status) {
if (Notification.permission !== status) {
Notification.permission = status;
}
});
}
})
</script>
`
}
app.get('*', function (req, res) {
res.send(getIndexPage())
})
app.use(Raven.errorHandler())
var PORT = parseInt(process.env.LEANCLOUD_APP_PORT || process.env.PORT || 8080)
app.listen(PORT, function() {
console.log('LeanTicket server running on:' + PORT)
})