require('dotenv').config()

const express = require('express');
const path = require('path');

const getAccessToken = require('./utilities/access_token')
const getBarsByLocation = require('./utilities/search.js')

const app = express();
const PORT = process.env.PORT || 5000;

// Priority serve any static files.
app.use(express.static(path.resolve(__dirname, '../react-ui/build')));


getAccessToken(process.env.CLIENT_ID,process.env.CLIENT_SECRET)
  .then((result) => {
    const ACCESS_TOKEN = result.access_token
    getBarsByLocation(ACCESS_TOKEN, '79416')
      .then((results) => console.log(results))
  })
  .catch(error => console.error(error))

// Answer API requests.
app.get('/api', function (req, res) {
  res.set('Content-Type', 'application/json');
  res.send('{"message":"Hello from the custom server!"}');
});

// All remaining requests return the React app, so it can handle routing.
app.get('*', function(request, response) {
  response.sendFile(path.resolve(__dirname, '../react-ui/build', 'index.html'));
});

app.listen(PORT, function () {
  console.log(`Listening on port ${PORT}`);
});

@@ -98,117 +98,37 @@
 nst 
-getAccessToken = require('./utilities/access_token')%0Aconst getBarsByLocation = require('./utilities/search.js
+yelp = require('./routes/yelp
 ')%0A%0A
@@ -302,449 +302,30 @@
 );%0A%0A
-%0AgetAccessToken(process.env.CLIENT_ID,process.env.CLIENT_SECRET)%0A  .then((result) =%3E %7B%0A    const ACCESS_TOKEN = result.access_token%0A    getBarsByLocation(ACCESS_TOKEN, '79416')%0A      .then((results) =%3E console.log(results))%0A  %7D)%0A  .catch(error =%3E console.error(error))%0A%0A// Answer API requests.%0Aapp.get('/api', function (req, res) %7B%0A  res.set('Content-Type', 'application/json');%0A  res.send('%7B%22message%22:%22Hello from the custom server!%22%7D');%0A%7D);
+app.use('/yelp', yelp)
 %0A%0A//

refactor api routes out into its own file