forked from Blockstream/esplora
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dev-server.js
41 lines (31 loc) · 1.14 KB
/
dev-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
import fs from 'fs'
import pug from 'pug'
import path from 'path'
import express from 'express'
import browserify from 'browserify-middleware'
import cssjanus from 'cssjanus'
const rpath = p => path.join(__dirname, p)
const app = express()
app.engine('pug', pug.__express)
app.use(require('morgan')('dev'))
if (process.env.CORS_ALLOW) {
app.use((req, res, next) => {
res.set('Access-Control-Allow-Origin', process.env.CORS_ALLOW)
next()
})
}
if (process.env.PRERENDER_URL) {
app.use((req, res, next) => {
if (req.query.nojs != null) return res.redirect(303, process.env.PRERENDER_URL+req.path)
next()
})
}
app.get('/', (req, res) => res.render(rpath('client/index.pug')))
app.get('/app.js', browserify(rpath('client/src/run-browser.js')))
app.get('/style-rtl.css', (req, res) =>
res.type('css').send(cssjanus.transform(fs.readFileSync(rpath('www/style.css')).toString(), false, true)))
app.use('/', express.static(rpath('www')))
app.use((req, res) => res.render(rpath('client/index.pug')))
app.listen(process.env.PORT || 5000, function(){
console.log(`HTTP server running on ${this.address().address}:${this.address().port}`)
})