const express = require('express'); const neo4j = require('neo4j-driver').v1; const winston = require('winston'); const cors = require('cors'); const jwt = require('express-jwt'); const gkeLogger = require('winston-gke'); // Pass when sitting behind load-balancer on a route (e.g. '/ledger-graph') const MOUNT_PATH = process.env.MOUNT_PATH || ''; // Initialize app, neo4j connection, logger and auth const app = express(); const neo = neo4j.driver(process.env.NEO_ADDRESS || 'bolt://neo4j', neo4j.auth.basic(process.env.NEO_USER || 'neo4j', process.env.NEO_PASS || 'neo4j')); const logger = gkeLogger(new winston.Logger()); const auth = jwt({ secret: new Buffer(process.env.AUTH_CLIENT_SECRET || '', 'base64'), audience: process.env.AUTH_CLIENT_ID || '' }); // Pull version from file if available let version; try { version = fs.readFileSync('./VERSION', 'utf-8').trim(); } catch (e) { version = 'local'; } // trust the proxies
const callbackToPromise = require('promise-callback') const logLevel = process.env.LOG_LEVEL || 'info' const port = process.env.PORT || 3001 const redisUri = process.env.REDIS_URI // do not let start process without the DB uri, helps devops if (!redisUri) { throw new Error('REDIS_URI is required') } const app = Express() const redis = Redis(redisUri) // configure winston for Google Cloud log format logger.remove(logger.transports.Console) winstonGke(logger, logLevel) // router app.get('/', (req, res) => { redis.get('foo') .then((foo) => res.json({ foo })) .catch((err) => next(err)) }) // health check app.get('/healthz', (req, res, next) => { redis.ping() .then(() => res.sendStatus(200)) .catch((err) => next(err))