无法发布/发布nodejs

时间:2012-06-20 14:10:56

标签: node.js content-management-system pug

我的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我已经使用了快速体解析器和方法ovveride

3 个答案:

答案 0 :(得分: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"}%

答案 1 :(得分:0)

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

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

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

答案 2 :(得分:0)

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