-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·58 lines (53 loc) · 1.26 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
import express from 'express'
import compression from 'compression'
import path from 'path'
import phpProxy from './fastcgi'
// const https = require("https")
// import fs from 'fs'
/*
const cert = {
key: '/etc/letsencrypt/live/example.com/privkey.pem',
cert: '/etc/letsencrypt/live/example.com/fullchain.pem'
}
*/
const phpFpmPort = 9000
const primaryPort = 80
// const sslPort = 443
const app = express()
app.use(compression())
// Add thrailing slash - always
app.use((req, res, next) => {
if (
req.path.substr(-1) !== '/' &&
req.path.length > 1 &&
req.path.split('/').pop().indexOf('.') === -1 &&
req.url.indexOf('?') === -1
) {
let query = req.url.slice(req.path.length)
res.redirect(301, req.path + '/' + query)
} else {
next()
}
})
/* Example to override routes
app.get('/example', (req, res) => {
res.send('example')
})
*/
app.get('/hey', (req, res) => {
res.send('Hey!')
})
app.use('/', phpProxy({
documentRoot: path.join(__dirname, '../public'),
env: {},
socketOptions: { port: phpFpmPort }
}))
app.listen(primaryPort, () => {
console.log('Webserver available at: http://localhost:' + primaryPort)
})
/*
https.createServer({
key: fs.readFileSync(cert.key),
cert: fs.readFileSync(cert.cert)
}, app).listen(sslPort)
*/