2

I'm using yeoman for my application which consists of 2 parts - client site with js/html/css and the rest service.

During development I start rest service in Eclipse and start server for my static files with

grunt server

The problem is that I have to do a post request to root url '/' (it's a fake login POST request to make browsers prompt to save passwords).

It worked with yeoman 0.9 but after updating I get:

Cannot POST /

Is there a way to configure grunt server task to accept POST requests?

0

1 Answer 1

1

I think you want the connect-rest middleware.

https://github.com/imrefazekas/connect-rest npm install connect-rest --save-dev

Edit Gruntfile.js, at the top

var restSupport = require('connect-rest');
   restSupport.post( { path: '/savequestion'}, function(req, content, next){
   next(null, {result: 'OK'});
});

In your connect or livereload middleware section:

        livereload: {
            options: {
                middleware: function (connect) {
                    return [
                        lrSnippet,
                        mountFolder(connect, '.tmp'),
                        mountFolder(connect, yeomanConfig.app),
                        restSupport.rester( {'context': '/forms'} ),
                        rewriteRulesSnippet, // RewriteRules support

The key part is "restSupport.rester()", remove the context if you don't want it.

This simple function should just reply with the json object {result: 'OK'} to everything you post to /forms/savequestion . It should at least let you build out scaffolding in grunt server :9000 mode before you have build your templates. Without this you would have to $.get() each $.post() and then change it during or after the build.

1
  • You can probably configure the top function to return whatever is in ?result so you can rapidly test errors as well as OK responses.
    – chugadie
    Aug 12, 2013 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.