{"size": 1556, "ext": "js", "max_stars_repo_path": "src/server/index.js", "max_stars_repo_name": "Thomas161/Travel_APP_Proj5", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/server/index.js", "max_issues_repo_name": "Thomas161/Travel_APP_Proj5", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/server/index.js", "max_forks_repo_name": "Thomas161/Travel_APP_Proj5", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.0967741935, "max_line_length": 67, "alphanum_fraction": 0.6632390746}
const place = require("../client/js/api/geonamesAPI");
const weather = require("../client/js/api/weatherbitAPI");
const pix = require("../client/js/api/pixabayAPI");
// const covid = require("../client/js/api/covid19API");

process.binding(
  "http_parser"
).HTTPParser = require("http-parser-js").HTTPParser;
const fetch = require("node-fetch");
const dotenv = require("dotenv");
dotenv.config();

const GEONAMES_USER = process.env.API_GEONAMES_USERNAME;
const PIXABAY_KEY = process.env.API_PIXABAY_KEY;
const WEATHER_KEY = process.env.API_WEATHERBIT_KEY;
const express = require("express");
const app = express();

const bodyParser = require("body-parser");
app.use(bodyParser.json());

const cors = require("cors");
app.use(cors());

app.use(express.static("dist"));

app.get("/test", (req, res) => {
  res.json({
    status: 200,
  });
});

app.listen(8080, () => {
  console.log(`Listening on 8080`);
});

app.post("/tripInfo", async (req, res) => {
  try {
    const city = req.body.city;
    const date = req.body.date;
    console.log("City in endpoint", city);
    let location = place.getCityDetail(GEONAMES_USER, city);
    let trip = await location;
    let mother = weather.getWeatherDetail(city, date, WEATHER_KEY);
    let trip2 = await mother;
    let im = pix.getImageDetail(city, PIXABAY_KEY);
    let trip3 = await im;

    res.json({
      trip: trip,
      trip2: trip2,
      trip3: trip3,

      errorMessage: new Error("Something went wrong"),
    });
  } catch (err) {
    console.log("error", err);
  }
});

module.exports = app;
