const url = require('url');
const _ = require('lodash');
const faker = require('faker');
const server = require('json-server');
const proxy = require('proxy-middleware');

const port = 3002;

const data = {
  repos: _.times(5, index => {
    const name = faker.random.word();
    return {
      id: index,
      name: name,
      description: faker.lorem.sentence(),
      html_url: `https://github.com/jas-chen/${name}`
    };
  })
};

const app = server.create();
const router = server.router(data);

// Mock API
app.use(server.defaults());
app.use('/users/jas-chen', router);
app.use('/', proxy(url.parse(`https://api.github.com/`)));

app.listen(port, (error) => {
  if (error) throw error;
  console.info(`server running at http://localhost:${port}`);
});

@@ -195,15 +195,82 @@
 nst 
-data = 
+app = server.create();%0A%0A// mock endpoint%0Aconst repoRouter = server.router(
 %7B%0A  
@@ -498,55 +498,60 @@
 %7D)%0A%7D
+)
 ;%0A%0A
-const app = server.create();
+// proxy to real api server
 %0Aconst 
-r
+proxyR
 outer = 
 serv
@@ -550,41 +550,53 @@
 r = 
-server.router(data);%0A%0A// Mock API
+proxy(url.parse(%60https://api.github.com/%60));%0A
 %0Aapp
@@ -620,24 +620,25 @@
 lts());%0A
+%0A
 app.use(
 '/users/
@@ -633,92 +633,164 @@
 use(
-'/users/jas-chen', router);%0Aapp.use('/', proxy(url.parse(%60https://api.github.com/%60))
+(req, res, next) =%3E %7B%0A  if (req.originalUrl === '/users/jas-chen/repos') %7B%0A    repoRouter(req, res, next);%0A    return;%0A  %7D%0A%0A  proxyRouter(req, res, next);%0A%7D
 );%0A%0A

update api server