小编xav*_*tic的帖子

Express bodyParser 无法正常工作

我有一个我无法弄清楚的 bodyparser 问题。

几周前,我使用 Express 创建了一个 REST API,并使用 bodyParser 从客户端读取 JSON 数据。一切正常,但今天早上我尝试启动我的应用程序,但我所有的 req.body.data 都未定义,实际上 body 等于 {}。

这是我的配置:

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
Run Code Online (Sandbox Code Playgroud)

然后我配置我的路线。我已经看到您必须按此顺序声明,即在您的路线之前声明 bodyParser,这就是我所做的。原以为是版本问题,但升级几次后问题依旧。

我使用 HttpRequester 来模拟客户端。直到今天早上一切正常。

发送的数据示例:

{
  "username": "david",
  "password": "bowie",
  "email": "db@sfr.fr"
}
Run Code Online (Sandbox Code Playgroud)

然后有这个响应代码:

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(logger('dev'));
app.use(expressValidator());
app.use(cookieParser());

app.use('/users', users);
Run Code Online (Sandbox Code Playgroud)

然后在用户中我只创建一个用户:

 // Creation of a user.
 router.post('/create', function(req, res) {

   // We check current mistakes like username or password empty.
   if (!userhelper.checkCreateUserRequest(req, res)) {
    return;
   }

   // Save the user in BDD …
Run Code Online (Sandbox Code Playgroud)

json express body-parser

4
推荐指数
1
解决办法
7636
查看次数

Prestashop 1.7无法显示自定义模块

我正在尝试prestashop 1.7,我在创建自定义模块时遇到了问题.我在"modules"文件夹中创建了一个文件夹"mymodule",并且正如文档中所示,我在其中创建了一个简单的mymodule.php文件:

<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

if (!defined('_PS_VERSION_'))
 exit;

class MyModule extends Module
{
  public function __construct()
  {
    $this->name = 'mymodule';
    $this->tab = 'front_office_features';
    $this->version = '1.0.0';
    $this->author = 'Firstname Lastname';
    $this->need_instance = 0;
    $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); 
    $this->bootstrap = true;

    parent::__construct();

    $this->displayName = $this->l('My module');
    $this->description …
Run Code Online (Sandbox Code Playgroud)

php prestashop prestashop-1.7

3
推荐指数
2
解决办法
3340
查看次数

标签 统计

body-parser ×1

express ×1

json ×1

php ×1

prestashop ×1

prestashop-1.7 ×1