Monday, 15 October 2018

Is there a better way to prepend '/api' before every one of my API endpoints?

So my app.js file is my base server file. I want to make it so that it uses other .js files containing API endpoints, like so:app.use('/api/users', require(./routes/users')); app.use('/api/posts', require(./routes/posts')); app.use('/api/comments', require(./routes/comments')); app.use('/api/subscriptions', require(./routes/subscriptions')); It looks pretty messy with all of the '/api' in there. All valid paths on this server will start with '/api'. What's a better way to do what I'm trying to achieve?

Submitted October 15, 2018 at 10:28PM by v_95

No comments:

Post a Comment