Skip to content

Commit

Permalink
[OZ-0003] fix for http/1 fallback and access logs
Browse files Browse the repository at this point in the history
Add workaround for http/1 fallback.
Reference: molnarg/node-http2#220
Add logging support
  • Loading branch information
zaknuces committed Mar 26, 2017
1 parent e4c785c commit 8ad9c73
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
logs
38 changes: 30 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
var express = require('express');
var fs = require('fs');
var http = require('http');
var http2 = require('http2');
var morgan = require('morgan');
var path = require('path');

// Create Express Application
var app = express();

express.request.__proto__ = http2.IncomingMessage.prototype;
express.response.__proto__ = http2.ServerResponse.prototype;
// Make HTTP2 work with Express (this must be before any other middleware)
require('express-http2-workaround')({ express: express, http2: http2, app: app });

// create a write stream (in append mode)
var logDirectory = './logs';
if (!fs.existsSync(logDirectory)){
fs.mkdirSync(logDirectory);
}
var accessLogStream = fs.createWriteStream(path.join(logDirectory, 'access.log'), {flags: 'a'})

var options = {
key: fs.readFileSync('./node_modules/http2/example/localhost.key'),
cert: fs.readFileSync('./node_modules/http2/example/localhost.crt')
};

app.use(express.static('public'));
http2
.createServer(options, app)
.listen(443, function() {
console.log("Express HTTP 2 server up and running.");
});

app.get('/', function (req, res) {
//res.send('Hello World');
res.redirect('/main.html');
});
http
.Server(app)
.listen(80, function() {
console.log("Express HTTP 1 server up and running.");
});

http2.createServer(options, app).listen(3001);
app
.use(morgan('combined', {stream: accessLogStream}))
.use(express.static('public'))
.get('/', function (req, res) {
res.redirect('/main.html');
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"license": "ISC",
"dependencies": {
"express": "^5.0.0-alpha.5",
"http2": "^3.3.6"
"express-http2-workaround": "^1.1.2",
"http2": "^3.3.6",
"morgan": "^1.8.1"
}
}
11 changes: 11 additions & 0 deletions public/devSessionList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/theme.css">
<script type="text/javascript" src="js/Application.js"></script>
<script type="text/javascript" src="js/DevSession.js"></script>
</head>
<body>
<div class="vox-header"> List of Dev Sessions </div>
<a class="option home" href="main.html">Home</a>
</body>
</html>
Binary file added public/images/singapore.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/js/Application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Application {
constructor() {}
};
3 changes: 3 additions & 0 deletions public/js/Configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Configuration {
constructor () {}
}
3 changes: 3 additions & 0 deletions public/js/DevSession.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class DevSession {
constructor () {}
}
4 changes: 4 additions & 0 deletions public/main.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/theme.css">
<script type="text/javascript" src="js/Application.js"></script>
<script type="text/javascript" src="js/Configuration.js"></script>
</head>
<body>
<div class="vox-header"> Hello World. </div>
<img src="images/singapore.jpeg" alt="SG" width="400" height="300"/>
<a class="option dev-session" href="devSessionList.html">List of Topics</a>
</body>
</html>

0 comments on commit 8ad9c73

Please sign in to comment.