Skip to content

Commit

Permalink
API v4: proxy v3 routes
Browse files Browse the repository at this point in the history
  • Loading branch information
paglias committed Jun 16, 2018
1 parent 97a0696 commit 19ecfef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import setupBody from './setupBody';
import routes from '../libs/routes';
import path from 'path';

const API_CONTROLLERS_PATH = path.join(__dirname, '/../controllers/api-v3/');
const API_V3_CONTROLLERS_PATH = path.join(__dirname, '/../controllers/api-v3/');
const TOP_LEVEL_CONTROLLERS_PATH = path.join(__dirname, '/../controllers/top-level/');

const v3app = express();
Expand All @@ -24,7 +24,13 @@ routes.walkControllers(topLevelRouter, TOP_LEVEL_CONTROLLERS_PATH);
v3app.use('/', topLevelRouter);

const v3Router = express.Router(); // eslint-disable-line new-cap
routes.walkControllers(v3Router, API_CONTROLLERS_PATH);
routes.walkControllers(v3Router, API_V3_CONTROLLERS_PATH);
v3app.use('/api/v3', v3Router);

// API v4 proxies API v3
// Can also disable or override with its own version v3 routes
const v4Router = express.Router(); // eslint-disable-line new-cap
routes.walkControllers(v4Router, API_V3_CONTROLLERS_PATH);
v3app.use('/api/v4', v4Router);

module.exports = v3app;
5 changes: 2 additions & 3 deletions website/server/middlewares/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from './redirects';
import v1 from './v1';
import v2 from './v2';
import v3 from './v3';
import appRoutes from './appRoutes';
import responseHandler from './response';
import {
attachTranslateFunction,
Expand Down Expand Up @@ -89,12 +89,11 @@ module.exports = function attachMiddlewares (app, server) {
}
app.use('/api/v2', v2);
app.use('/api/v1', v1);
app.use(v3); // the main app, also setup top-level routes
app.use(appRoutes); // the main app, also setup top-level routes
staticMiddleware(app);

app.use(notFoundHandler);

// Error handler middleware, define as the last one.
// Used for v3 and v1, v2 will keep using its own error handler
app.use(errorHandler);
};

0 comments on commit 19ecfef

Please sign in to comment.