Skip to content

feat(cli): allow assign routes with express.Route() in file JS #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ramonornela
Copy link

@ramonornela ramonornela commented Nov 20, 2016

This PR allow building routes custom using express.router() in source file JS

json-server router.js

Use case ex: router.js

var path = require('path');

module.exports = function() {
	var express = require('express');

	var router = function(router) {
		var expressRouter = express.Router();

		expressRouter.get('/news/me', function(req, res) {
		  var new =  router.db
                           .get('news')
			               .find({ id: 1 })
			               .value();
		  res.json(new);
		});

		return expressRouter;
	}

	return {
		"__source": path.join(__dirname, 'db.json'),
		"__router": router
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant