{"size": 2994, "ext": "js", "max_stars_repo_path": "test/docker/metadata/metadata.js", "max_stars_repo_name": "JLXIA/esp", "max_stars_repo_stars_event_min_datetime": "2017-07-12T17:05:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T14:25:21.000Z", "max_issues_repo_path": "test/docker/metadata/metadata.js", "max_issues_repo_name": "JLXIA/esp", "max_issues_repo_issues_event_min_datetime": "2017-06-07T21:56:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T14:46:34.000Z", "max_forks_repo_path": "test/docker/metadata/metadata.js", "max_forks_repo_name": "JLXIA/esp", "max_forks_repo_forks_event_min_datetime": "2017-06-07T20:51:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T15:30:12.000Z"}
{"max_stars_count": 275, "max_issues_count": 322, "max_forks_count": 125, "avg_line_length": 39.3947368421, "max_line_length": 106, "alphanum_fraction": 0.6837007348}
// Copyright (C) Extensible Service Proxy Authors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
//
////////////////////////////////////////////////////////////////////////////////
//

"use strict";
var express = require('express');
function metadata() {
  var metadata = express();
  // Tracing middleware.
  metadata.use(function(req, res, next) {
    console.log(req.method, req.originalUrl);
    console.log(req.headers);
    console.log();
    next();
  })
  metadata.get('/', function(req, res) {
    res.send(process.env.ACCESS_TOKEN);
  });
  metadata.get('/computeMetadata/v1/instance/attributes/endpoints-service-name', function(req, res) {
    res.send('bookstore-backend.endpointsv2.appspot.com');
  });
  /*
  metadata.get('/computeMetadata/v1/instance/attributes/endpoints-service-config-id', function(req, res) {
    res.send('2016-04-25R1');
  });
  */
  metadata.get('/computeMetadata/v1/', function(req, res) {
    res.set('Content-Type', 'application/json');
    res.sendFile('metadata.json', { root: __dirname });
  });
  metadata.get('/computeMetadata/v1/instance/service-accounts/default/token',
    function(req, res) {
      res.set('Content-Type', 'application/json');
      res.set('Metadata-Flavor', 'Google');
      res.send({
        'access_token':process.env.ACCESS_TOKEN,
        'expires_in':3592,
        'token_type':'Bearer'
      });
    });
  return metadata;
}
if (module.parent) {
  module.exports = metadata;
} else {
  var server = metadata().listen(process.env.PORT ||
    process.env.METADATA_PORT || '8080', '0.0.0.0', function() {
    var host = server.address().address;
    var port = server.address().port;
    console.log('Metadata listening at http://%s:%s', host, port);
  })
}
