0

我的 app.coffee 中的代码它使用咖啡脚本我已经放置了正文解析器和方法 ovveride

           express = require("express")
          everyauth = require("everyauth")
             should = require("should")
        fs = require("fs")

      everyauth.debug = true
        usersByLogin = krishna:
          login: "krishna"
          email: "krishna@blogab.com"
             password: "krishna"

          everyauth.password.loginWith("login").getLoginPath("/login").postLoginPath("        
       /login").loginView("bcore/login.jade").loginLocals((req, res, done) ->
      setTimeout (->
       done null,
           title: "blogab - login"
          ), 200
         ).authenticate((login, password) ->
      errors = []
        errors.push "Missing login"  unless login
       errors.push "Missing password"  unless password
       return errors  if errors.length
         user = usersByLogin[login]
        return [ "Login failed" ]  unless user
        return [ "Login failed" ]  if user.password isnt password
      user
       ).getRegisterPath("/register").postRegisterPath("    

         /register").registerView("bcore                 

         /register.jade").registerLocals((req, res, done) ->
      setTimeout (->
         done null,
            title: " Register"
          ), 200
           ).extractExtraRegistrationParams((req) ->
        email: req.body.email
       ).validateRegistration((newUserAttrs, errors) ->
        login = newUserAttrs.login
        errors.push "Login already taken"  if usersByLogin[login]
        errors
         ).registerUser((newUserAttrs) ->
            login = newUserAttrs[@loginKey()]
             usersByLogin[login] = newUserAttrs
           ).loginSuccessRedirect("/admin").registerSuccessRedirect "/admin"
                    app =  express.createServer

          (express.bodyParser(),express.methodOverride(),     
             express.static(__dirname + "/public"),


                 express.session(secret: "htuayreve"),  everyauth.middleware())

              express.cookieParser(), 
               app.configure ->
             app.set "view engine", "jade"

            app.get "/", (req, res) ->
         res.render "templates/default/index",
          title: "blogab"
          users: JSON.stringify(usersByLogin, null, 2)

         app.get "/admin", (req, res) ->
         res.render "bcore/admin",
         title: "Blogab-admin"
          users: JSON.stringify(usersByLogin, null, 2)

           app.get "/login", (req, res) ->
            res.render "bcore/login",
             title: "login"
             users: JSON.stringify(usersByLogin, null, 2)

               app.get "/post", (req, res) ->
                   res.render "bcore/viewpost",
                    title: "login"
                    users: JSON.stringify(usersByLogin, null, 2)

            app.get "/admin/post/new", (req, res) ->
            res.render "bcore/newpost",
           title: "Blogab-newpost"
            users: JSON.stringify(usersByLogin, null, 2)

       everyauth.helpExpress app
         app.listen 1224, ->
          console.log "blogab is  running on port %d in %s mode",
            app.address().port,   app.setting

在 newpost.jade 中是 newpost 的代码

            !!! 5
           html(xmlns='http://www.w3.org/1999/xhtml')
           head
           title
          link(href='/css/master.css', rel='stylesheet', type='text/css')
          body
           h1
           | New post
           form#new_post.new_post(method='post', action='/posts')
             .field
              label(for='post_title') Title
               br
                 input#post_title(type='text', name='title', size='30')
           .field
              label(for='post_content') Content
            br
               textarea#post_content(name='content', cols='40', rows='20')
          .actions
              input#post_submit(type='submit', value='Create Post')
            p
               br
                 a(href='/posts') Back

当我单击在 newpost.jade 中发布它时,它说无法发布/发布,我正在创建基于 nodejs 的 cms,我使用了 express body parser 和方法 ovveride

4

3 回答 3

1

好像您忘记定义 POST /posts 路由:

app.get '/posts', (req, res, next) ->

编辑添加一个例子,你的代码真的很难阅读。我写了这个:

express = require 'express'
app = express.createServer()

app.configure ->
  app.use express.methodOverride()
  app.use express.bodyParser()
  app.use app.router

app.post '/posts', (req, res) -> res.send req.body

app.listen 3000

$ curl localhost:3000/posts -X POST -d "param1=value1&param2=value2"

{"param1":"value1","param2":"value2"}%

于 2012-06-20T14:30:34.030 回答
0

如果您想发布数据来表达,您必须使用 POST 动词定义您的路线:

app.post '/posts', (req, res) ->

另外,我不确定您是否要将路由定义为“/post”或“/posts”,因此请仔细检查客户端和服务器代码是否匹配。

于 2012-06-20T15:32:52.890 回答
0

app.get无法发布数据,请尝试始终使用app.post发布数据。它对我有用:)

于 2017-03-07T03:33:45.600 回答