【问题标题】:Express Req.body empty on one PC but works fine on anotherExpress Req.body 在一台 PC 上为空,但在另一台 PC 上工作正常
【发布时间】:2020-12-06 12:57:51
【问题描述】:

我在 1 台电脑上有一个 Firebase Express JS 项目文件夹。 当我运行 firebase serve 时,一切正常。

我正在尝试将我的工作 PC 更改为另一台。 我已经设置了我的 nodejs、firebase cli,并在这台新 PC 上打开了相同的文件夹(通过 OneDrive,所有文件都在本地可用)

但是,当我运行 firebase serve 并尝试 POST 时,我看到 req.body 是空的。

我错过了什么吗?


工作PC的调试日志显示

[debug] [2020-12-19T09:39:00.832Z] Accepted request POST /project_path/sessionLogin --> app_name

当非工作电脑的调试日志显示时

[debug] [2020-12-19T09:34:13.542Z] <<< [apiv2][status] POST http://localhost:5001/project_path/sessionLogin 500
[debug] [2020-12-19T09:34:13.542Z] <<< [apiv2][body] POST http://localhost:5001/project_path/sessionLogin [stream]
[info] i  hosting: 127.0.0.1 - - [19/Dec/2020:09:34:13 +0000] "POST /sessionLogin HTTP/1.1" 500 2257 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" {"metadata":{"emulator":{"name":"hosting"},"message":"127.0.0.1 - - [19/Dec/2020:09:34:13 +0000] \"POST /sessionLogin HTTP/1.1\" 500 2257 \"http://localhost:5000/\" \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36\""}}
[info] >  TypeError: Cannot read property 'toString' of undefined {"user":"TypeError: Cannot read property 'toString' of undefined","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m TypeError: Cannot read property 'toString' of undefined"}}
[info] >      at C:\Users\name\firebase_files\functions\index.js:4059:38 {"user":"    at C:\\Users\\name\\firebase_files\\functions\\index.js:4059:38","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at C:\\Users\\name\\firebase_files\\functions\\index.js:4059:38"}}
[info] >      at Layer.handle [as handle_request] (C:\Users\name\firebase_files\functions\node_modules\express\lib\router\layer.js:95:5) {"user":"    at Layer.handle [as handle_request] (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\layer.js:95:5)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at Layer.handle [as handle_request] (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\layer.js:95:5)"}}
[info] >      at next (C:\Users\name\firebase_files\functions\node_modules\express\lib\router\route.js:137:13) {"user":"    at next (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\route.js:137:13)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at next (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\route.js:137:13)"}}
[info] >      at Route.dispatch (C:\Users\name\firebase_files\functions\node_modules\express\lib\router\route.js:112:3) {"user":"    at Route.dispatch (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\route.js:112:3)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at Route.dispatch (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\route.js:112:3)"}}
[info] >      at Layer.handle [as handle_request] (C:\Users\name\firebase_files\functions\node_modules\express\lib\router\layer.js:95:5) {"user":"    at Layer.handle [as handle_request] (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\layer.js:95:5)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at Layer.handle [as handle_request] (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\layer.js:95:5)"}}
[info] >      at C:\Users\name\firebase_files\functions\node_modules\express\lib\router\index.js:281:22 {"user":"    at C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:281:22","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:281:22"}}
[info] >      at Function.process_params (C:\Users\name\firebase_files\functions\node_modules\express\lib\router\index.js:335:12) {"user":"    at Function.process_params (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:335:12)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at Function.process_params (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:335:12)"}}
[info] >      at next (C:\Users\name\firebase_files\functions\node_modules\express\lib\router\index.js:275:10) {"user":"    at next (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:275:10)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at next (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:275:10)"}}
[info] >      at urlencodedParser (C:\Users\name\firebase_files\functions\node_modules\body-parser\lib\types\urlencoded.js:100:7) {"user":"    at urlencodedParser (C:\\Users\\name\\firebase_files\\functions\\node_modules\\body-parser\\lib\\types\\urlencoded.js:100:7)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at urlencodedParser (C:\\Users\\name\\firebase_files\\functions\\node_modules\\body-parser\\lib\\types\\urlencoded.js:100:7)"}}
[info] >      at Layer.handle [as handle_request] (C:\Users\name\firebase_files\functions\node_modules\express\lib\router\layer.js:95:5) {"user":"    at Layer.handle [as handle_request] (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\layer.js:95:5)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at Layer.handle [as handle_request] (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\layer.js:95:5)"}}
[info] >      at trim_prefix (C:\Users\name\firebase_files\functions\node_modules\express\lib\router\index.js:317:13) {"user":"    at trim_prefix (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:317:13)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at trim_prefix (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:317:13)"}}
[info] >      at C:\Users\name\firebase_files\functions\node_modules\express\lib\router\index.js:284:7 {"user":"    at C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:284:7","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:284:7"}}
[info] >      at Function.process_params (C:\Users\name\firebase_files\functions\node_modules\express\lib\router\index.js:335:12) {"user":"    at Function.process_params (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:335:12)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at Function.process_params (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:335:12)"}}
[info] >      at next (C:\Users\name\firebase_files\functions\node_modules\express\lib\router\index.js:275:10) {"user":"    at next (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:275:10)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at next (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\index.js:275:10)"}}
[info] >      at jsonParser (C:\Users\name\firebase_files\functions\node_modules\body-parser\lib\types\json.js:119:7) {"user":"    at jsonParser (C:\\Users\\name\\firebase_files\\functions\\node_modules\\body-parser\\lib\\types\\json.js:119:7)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at jsonParser (C:\\Users\\name\\firebase_files\\functions\\node_modules\\body-parser\\lib\\types\\json.js:119:7)"}}
[info] >      at Layer.handle [as handle_request] (C:\Users\name\firebase_files\functions\node_modules\express\lib\router\layer.js:95:5) {"user":"    at Layer.handle [as handle_request] (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\layer.js:95:5)","metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"\u001b[90m> \u001b[39m     at Layer.handle [as handle_request] (C:\\Users\\name\\firebase_files\\functions\\node_modules\\express\\lib\\router\\layer.js:95:5)"}}
[info] i  functions: Finished "app_name" in ~1s {"metadata":{"emulator":{"name":"functions"},"function":{"name":"app_name"},"message":"Finished \"app_name\" in ~1s"}}

【问题讨论】:

    标签: node.js express firebase-hosting


    【解决方案1】:

    您应该运行npm install 以确保所有软件包都已正确安装。您的控制台中没有错误消息吗?

    【讨论】:

    • 我试过了,但也没有用。是的,控制台中有错误,我已将其添加到我的问题中。
    • 老实说,这可能是很多事情。如果你愿意,我愿意帮助你。您能否提供更多代码,例如您正在调用的端点?其他 POST 端点是否也在工作或返回未定义?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-31
    • 2023-02-10
    • 1970-01-01
    相关资源
    最近更新 更多