C
C
coderisimo2019-12-04 22:18:28
Yii
coderisimo, 2019-12-04 22:18:28

What is the best way to implement the front in Vue and the back in Yii (preferably without CORS)?

The standard recommendation is to make two subdomains.
Ok, but then everyone's favorite CORS comes into play. It's configurable (there's a lot of fun there too!), but it will constantly send PREFLIGHT requests for so-called "complex" requests. Ie the place of one request will be two. Of course, this does not speed up the site (and infuriates!).
There will be no such bifurcation only for so-called 'simple' queries. For example, for GET - it is considered simple if the rest of the set of rules is followed. But, there is one thing: if you use (and you use!) bearer tokens , then your request is no longer considered simple, because there is a corso-nasty Authorization header. So, our favorite double requests are back in business.
Of course, we can try to cache these OPTIONS , but many browsers spit on our desires from a high bell tower. And the caching time is limited to 600 seconds. So it doesn't give a significant gain. You can also remove the Authorization header and send the token directly in the request, which is also ugly (and we want beauty and correctness).
Accordingly, what to do? ))
Vue wants to be a separate application. When working in a kosher way through the CLI (conveniently!) generates its own folder. How to slip it into Yii so that everything works without dancing, CORS and other fun things? I do not need a REST API (although I have already written and configured it), I need it to work quickly and without unnecessary complications. Or is that not the case nowadays?
I used to do everything in a clumsy way, including js files in Yii templates And so on. For advanced people, this causes nightmares. Now I want to do it "as expected", separate the flies (Yii) and cutlets (Vue). However, I do not want to get brakes only because of the advanced (moved?) architecture.
Share your thoughts.
Thank you!
Threat I heard something about a reverse proxy, as a solution to this problem. But I'm afraid I won't be able to do it either. So I spent a week mastering fancy consoles, webpacks, setting up two subdomains, learning postman, cors, and more. In the old fashioned way, stuffing everything into Yii views would have done everything a long time ago.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alex Wells, 2019-12-05
@coderisimo

For the backend, allocate a backend subdomain on the same domain as the front. Set it up to work.
Then, in the front config, add the location to /backend/, where the Host header with the full backend domain (i.e. backend.domain.com) and proxy_pass to 127.0.0.1.
Although 500ms is complete nonsense. Ping to the states - 200ms mountain. How 500-600 comes out there is a mystery.

A
Alexander Aksentiev, 2019-12-04
@Sanasol

OPTIONS contains practically no logic on the backend, except to check the authorization, why are you so bombed by it? Total is performed <50ms, well, then it depends on the Internet.
"Repaired" with two headlines and no longer bothers.
The whole backend has long understood OPTIONS.
And bomb from the corsa, but all you had to do was find out that it only works between different domains, so why not just raise the backend and front on the same domain?

X
xmoonlight, 2019-12-05
@xmoonlight

I do not need a REST API (although I have already written and configured it), I need it to work quickly and without unnecessary complications. Or is that not the case nowadays?
Why an API? Why vue? Why Yii? Didn't you think that the complexity is in the tools used?
Take it and make it so that there is no API / CORS and a cloud of performance-consuming unnecessary nested OOP classes in PHP ( for those who can code normally! ).
fetch() for json! with GET/POST method and Content-type: text/plain
Do you want to quickly change markup blocks without reloading the page and without any CORS?
Easy: includeHTML (one line!)

T
tolalur, 2019-12-05
@tolalur

Good evening.
Vue wants to be a separate application. When working in a kosher way through the CLI (conveniently!) generates its own folder. How to slip it Yii,
Haven't done anything in Yii for a hundred years, so don't judge too harshly.
When deploying for production in the template (I'm talking about the Yii template) in which you want Vue, give what you got from the dist folder when building the Vue application. When developing a Vue application, simply proxy all requests to the Yii endpoint

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question