This repository was archived by the owner on Aug 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
97 lines (74 loc) · 3.08 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
//=======================================================
// Declarations
//=======================================================
const express = require('express')
const ms = require('ms')
const nunjucks = require('nunjucks')
const rootDir = require('path').resolve('.') + '/'
const staticOptions = {
maxAge: process.env.NODE_ENV === 'production' ? ms('1d') : ms('1s')
}
const app = express()
const blackAngusData = require('./data/blackangus')
const tagliereData = require('./data/tagliere')
//=======================================================
// Template Engine
//=======================================================
const loader = new nunjucks.FileSystemLoader(`${rootDir}/views`, { watch: false, noCache: true })
const tmplEnv = new nunjucks.Environment(loader, { autoescape: false })
app.locals.env = process.env.NODE_ENV
tmplEnv.addGlobal('env', process.env.NODE_ENV)
tmplEnv.express(app)
//=======================================================
// Static Routes
//=======================================================
app.use('/plugins', express.static('plugins', staticOptions), notFoundHandler)
app.use('/assets', express.static(`assets`, staticOptions), notFoundHandler)
app.use('/dist', express.static(`dist`, staticOptions), notFoundHandler)
app.use('/views', express.static(`views`, staticOptions), notFoundHandler)
//=======================================================
// Stripe Routes
//=======================================================
app.get('/stripe/connect/authorize', function(req, res, next) {
// Stripe Authorization Route Goes Here
// const query = qs.stringify(params)
// res.redirect(`https://connect.stripe.com/oauth/authorize?${query}`)
})
app.get('/stripe/connect/callback', function(req, res, next) {
// Decrypt and verify req.query.state
res.status(200).end('Stripe account connected')
})
//=======================================================
// Application Routes
// The following are not real Routes
// They are for demonstration convenience only
//=======================================================
app.get('*/blackangus', function(req, res, next) {
res.render('index.html', { page: 'vendor', vendor: blackAngusData })
})
app.get('*/tagliere', function(req, res, next) {
res.render('index.html', { page: 'vendor', vendor: tagliereData })
})
app.get('*/checkout', function(req, res, next) {
res.render('index.html', { page: 'vendor/checkout' })
})
app.get('*/:page', function(req, res, next) {
res.render('index.html', { page: req.params.page })
})
//=======================================================
// Error Handlers
//=======================================================
function notFoundHandler(req, res, next) {
return res.status(404).end()
}
app.use(notFoundHandler)
app.use(function(err, req, res, next) {
res.status(500).end(err.message)
})
//=======================================================
// Start Server
//=======================================================
const server = app.listen(8080, function() {
const port = server.address().port
console.log(`Started 1000 Fooodies on port ${port}`)
})