Skip to content

Instantly share code, notes, and snippets.

Created March 27, 2017 08:09
Show Gist options
  • Save haruiz/b24b0a4fa94e0d30e2635012501e5c58 to your computer and use it in GitHub Desktop.
Save haruiz/b24b0a4fa94e0d30e2635012501e5c58 to your computer and use it in GitHub Desktop.
//const robot = require("./Robot")("Cyg");
const hapi = require("hapi");
const boom = require("boom");
const path = require("path");
const ngrok = require('ngrok');
const bluebird = require("bluebird");
const fs = require("fs");
const Robot = require("./Robot");
const config = JSON.parse(fs.readFileSync("./config.json","utf8"));
const meRobot = new Robot("Cyg", config);
const port = 8080;
const server = new hapi.Server();
server.connection({ port: port, host: '' });
async function setup() {
await server.register(require("inert"));
ngrok.connect(port,function (err, url) {
setup().then(() => {
path: "/stt",
method: "POST",
config: {
payload: {
output: 'stream',
maxBytes: 1048576 * 10, /*10MB*/
parse: true,
allow: 'multipart/form-data'
handler: (request,reply)=>{
var audioAsBinary =;
//we order to the robot that please, convert the audio into Text
//for guessing the command that the user is sending, for example take a picture
//handler to sucess request
.then((data)=>{ return reply(data)})
//hanlder to error request
.catch((err)=> { console.log(err); return reply(err)});
//the route just send to user the index.html file where all happen
path: "/robot",
method: "GET",
handler: {
file: {
path: "./views/index.html"
//once ngrok have generated the uri, the using it
//we redirect the user at /robot route
path: "/",
method: "GET",
handler: (request,reply)=>{
return reply().redirect(`${url}/robot`);
//this route let us handler the static content as
//jquery, axios and others frontend component (css, images etc.)
path: "/assets/{path*}",
method: "GET",
handler: {
directory: {
path: "./public"
server.start(() => console.log(`the port is running at ${}`));
//process.on('SIGINT', function() { ngrok.disconnect(); ngrok.kill(); /* kills ngrok process */ });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment