K
K
KhD2018-07-27 10:17:33
Django
KhD, 2018-07-27 10:17:33

How to fix data loss in nginx POST requests?

When sending POST data with a request to the server, nginx makes a 301 redirect and the data from the request body is lost. Can this be fixed?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
RidgeA, 2018-07-27
@RidgeA

It is better, of course, to do it right away to the correct address, but you can just do a proxy_pass to the desired address, although this is not quite a replacement ...
Another option is to replace the status with 308 ...

D
Dmitry Entelis, 2014-12-19
@DmitriyEntelis

1) https://ru.wikipedia.org/wiki/Model-View-Controller
2) It seems to me that it would be more useful for you to look at some normal framework like Yii2.
WordPress is just classic shit code.

L
Lesha Kiselev, 2014-12-19
@Yakud

Read about patterns. The book "Clean Code" helped me a lot ( www.ozon.ru/context/detail/id/21916535/).
Do not complicate your program, if it can be made easier - do it.
Don't write too much. If it is not required now, then it is not worth writing.
In your case, I see the following structure:
There is a connection pool class (eg ConnectionPool ). At the input it takes a string - the name of the repository, at the output it gives the connection to the database.
We break the program into entities: User , News , Page .
Each entity has its own storage: UserStorage , NewsStorage , PageStorage. The repository is only concerned with managing the entity in the database: save , load , delete , etc.
When created, the repository takes a connection to the database and saves it "in itself".
The code will look something like this:

$Connection = ConnectionPool::getConnection('users');
$UsersStorage = new UserStorage($Connection);

$User = $UsersStorage->loadById(1);
$User->set('name', 'Yakob');
$User->get('name');
$UserStorage->save($User);
$UserStorage->delete($User);

Same with other entities.
The connection between the entities and the storages is immediately traced. We select an abstraction, for example AbstractStorage. We take out the common parts of the storages into it.
The above storage creation code can be hidden, for example, behind a facade like this:
class UserFacade {
    protected static $UserStorage = null;

    public static function getById($id) {
        return self::getUserStorage()->getById($id);
    }

    public static function save(User $User) {
        return self::getUserStorage()->save($User);
    }

    protected static function getUserStorage() {
        if (is_null(self::$UserStorage)) {
            $Connection =  ConnectionPool::getConnection('users');
            self::$UserStorage = new UserStorage($Connection);
        }

        return self::$UserStorage;
    }
}

Everything else is different business logic. Need to get user news? We create a class for example UsersNewsStorage , which is inherited from NewsStorage . There is a getFeed method.
The code looks something like this:
....
$User = $UserStorage->getById(1);
$UsersNewsStorage = new UsersNewsStorage($Connection);
$Feeds = $UsersNewsStorage->getFeed($User);

Need news validation? We do not touch the storage ( NewsStorage ), it only does what it does. The rest is business logic.
Adding validation to UsersNewsStorage .
$User = $UsersStorage->loadById(1);
$News = new News(['title'=>'AAA', 'body'=>'bbbbbb']);
$UsersNewsStorage = new UsersNewsStorage($Connection);
try {
  $UsersNewsStorage->saveNews($User, $News); // Внутри валидация
} catch (ValidationNewsErrorException $Ex) {
  // Валидация не прошла
}

Thus, we take responsibility and business logic out of the main classes, define dependencies in the code. At any time, we can replace one piece without breaking the rest of the code.
If something is not clear, ask questions. The topic is very large and requires questions.

S
Stanislav, 2014-12-19
@mzcoding

As previously recommended, you need to understand and apply design patterns. A couple of books for review, which will definitely help www.ozon.ru/context/detail/id/5648968 and www.ozon.ru/context/detail/id/2457392/.
Also install and use some Yii or Laravel framework for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question