-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate web frontend out into its own service
This will make ghviz easier to dockerize as well as opens up a path towards server side rendering.
- Loading branch information
Showing
10 changed files
with
129 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ services/web/web | |
|
||
npm-debug.log | ||
|
||
dashboard/dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import express, { Router } from 'express'; | ||
import fs from 'fs'; | ||
import hogan from 'hogan.js'; | ||
import httpProxy from 'http-proxy'; | ||
import { includes } from 'lodash'; | ||
import morgan from 'morgan'; | ||
import { parse } from 'url'; | ||
import process from 'process'; | ||
|
||
const app = express(); | ||
const router = Router(); | ||
const indexTpl = hogan.compile(fs.readFileSync('./index.tpl.html', 'utf-8')); | ||
const proxy = httpProxy.createProxyServer({ | ||
target: `${process.env.GHVIZ_API_URL}/`, | ||
}); | ||
|
||
proxy.on('proxyReq', (proxyReq, req) => { | ||
proxyReq.path = parse(req.url).path.replace(/^\/gh/, ''); | ||
}); | ||
|
||
router.all('/gh/*', (req, res) => { | ||
proxy.web(req, res, {}); | ||
}); | ||
|
||
router.get('/', (req, res) => { | ||
res.send(indexTpl.render({ | ||
owner: process.env.GHVIZ_OWNER, | ||
repo: process.env.GHVIZ_REPO, | ||
})); | ||
}); | ||
|
||
function getConfiguredPort() { | ||
if (process.env.GHVIZ_WEB_PORT) { | ||
const integerPort = (process.env.GHVIZ_WEB_PORT|0); | ||
if (0 < integerPort && integerPort < 65536) { | ||
return integerPort; | ||
} | ||
} | ||
return 4001; | ||
} | ||
|
||
const ALLOWED_STATIC_FILES = [ | ||
'/bundle.js', | ||
'/bundle.js.map', | ||
'/bundle.min.js', | ||
'/bundle.min.js.map', | ||
'/main.css', | ||
'/node_modules/bootstrap/dist/css/bootstrap.min.css', | ||
'/node_modules/bootstrap/dist/css/bootstrap.min.css.map', | ||
'/third_party/octicons/octicons.css', | ||
'/third_party/octicons/octicons.ttf', | ||
'/third_party/octicons/octicons.woff', | ||
]; | ||
|
||
function restrictDashboardStaticFiles(req, res, next) { | ||
if (!includes(ALLOWED_STATIC_FILES, req.path)) { | ||
return res.sendStatus(404); | ||
} | ||
next(); | ||
} | ||
|
||
app.use(morgan('short')); | ||
app.use(router); | ||
app.use('/dashboard', restrictDashboardStaticFiles, express.static('.')); | ||
const configuredPort = getConfiguredPort(); | ||
app.listen(configuredPort, function () { | ||
/*eslint-disable no-console*/ | ||
console.log(`${process.argv[1]} listening on port ${configuredPort}`); | ||
/*eslint-enable no-console*/ | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var fs = require('fs'); | ||
var _ = require('lodash'); | ||
|
||
/*global __dirname*/ | ||
|
||
exports.externals = _.fromPairs(_.map( | ||
_.filter(fs.readdirSync('node_modules'), function (dir) { | ||
return ['.bin'].indexOf(dir) === -1; | ||
}), | ||
function (module) { | ||
return [module, 'commonjs ' + module]; | ||
}) | ||
); | ||
|
||
exports.entry = './server.js'; | ||
|
||
exports.target = 'node'; | ||
|
||
exports.output = { | ||
path: path.join(__dirname, 'dist'), | ||
filename: 'server.js', | ||
}; | ||
|
||
exports.module = { | ||
loaders: [{ | ||
exclude: /node_modules/, | ||
loader: 'babel', | ||
query: { presets: ['es2015', 'react', 'stage-2'] }, | ||
test: /\.js$/, | ||
}], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters