This repository was archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver.js
99 lines (83 loc) · 2.6 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
const express = require('express')
const expressStaticGzip = require('express-static-gzip')
const path = require('path')
const timeout = require('connect-timeout')
// if (!process.env.DATABASE_URL) {
// const env = require('node-env-file')
// env(path.join(__dirname, '.env'))
// }
const app = express()
// Serve static files
app.use('/static', express.static(path.join(__dirname, 'dist/')))
app.use('/', expressStaticGzip(path.join(__dirname, 'dist'), { indexFromEmptyFile: false }))
// app.use(express.static(path.join(__dirname, 'dist')))
app.use(bodyParser.json({
limit: '50mb',
// For Stripe webhooks, we compute the raw body so its signature can be verified
verify: (req, res, buf) => {
const url = req.originalUrl
if (url.startsWith('/webhooks')) {
req.rawBody = buf.toString()
}
},
}))
app.use(cookieParser(process.env.SESSION_COOKIE_SECRET))
app.use(timeout(15000))
// Serve public landing page
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'dist', 'index.html'))
})
// Serve legal documents
app.get('/privacy', (req, res) => {
res.sendFile(path.join(__dirname, 'legal', 'privacy.html'))
})
app.get('/terms', (req, res) => {
res.sendFile(path.join(__dirname, 'legal', 'terms.html'))
})
// Serve press kit
app.get('/press', (req, res) => {
res.sendFile(path.join(__dirname, 'press', 'press.html'))
})
// Database ORM
// const knex = require('./db')
// const { db, dbReady } = require('./models/_index')(knex)
const serverReady = Promise.resolve(true).then(() => {
// Configure passport auth
// require('./passport/config')(passport, knex)
// Auth sessions
// const sessionStore = new KnexSessionStore({
// knex
// })
// app.set('trust proxy', 1)
// app.use(session({
// store: sessionStore,
// saveUninitialized: false,
// secret: process.env.SESSION_COOKIE_SECRET,
// resave: false,
// cookie: {
// maxAge: 30 * 24 * 60 * 60 * 1000, // 7 days
// // Set "null" for a temporary cookie (expires when browser session ends)
// secure: process.env.INSECURE_COOKIES !== 'true',
// },
// }))
// app.use(passport.initialize())
// app.use(passport.session())
// REST APIs
// require('./api/_index')(app, passport, db)
// Log errors
app.use((err, req, res, next) => {
if (err) {
console.error(err)
}
next()
})
// Listen
const port = process.env.PORT || 3000
app.server = app.listen(port, () => {
console.log(`Express listening on port ${port}`)
})
return true
})
module.exports = { app, serverReady }