Skip to content

Commit

Permalink
Swap out fledgling Flask application for a Node Express one,
Browse files Browse the repository at this point in the history
Investigation revealed that Web3.py couldn't read the events raise
by our smart contract. This was, apparently, a problem in the Solidity
compiler rather than Web3.py, but that's little consolation as it means
I can't use it.  Switching to a JavaScript backend because we know
Web3.js works ok, even though it means we'll have to shell out to
run the image fingerprinter.
  • Loading branch information
jezhiggins committed Aug 1, 2019
1 parent 9ec4986 commit 7eee688
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.venv
node_modules
package-lock.json

17 changes: 0 additions & 17 deletions web-server/angels-wings.py

This file was deleted.

14 changes: 14 additions & 0 deletions web-server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const express = require('express');
const path = require('path');
const logger = require('morgan');

const app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

app.get('/', (req, res) => res.redirect(301, '/index.html'));
app.use(express.static(path.join(__dirname, 'static')));

module.exports = app;
90 changes: 90 additions & 0 deletions web-server/bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

const app = require('../app');
const debug = require('debug')('web-server:server');
const http = require('http');

/**
* Get port from environment and store in Express.
*/

const port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

const server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
const port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

const bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
const addr = server.address();
const bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
14 changes: 14 additions & 0 deletions web-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "web-server",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.1",
"morgan": "~1.9.1"
}
}

0 comments on commit 7eee688

Please sign in to comment.