Comments (4)
Hi @ihormartyniuk,
Good to hear and thank you for sharing the solution.
Hope you have good day.
Chris
from yii2-angular-boilerplate.
Hey @ihormartyniuk
For fixing 415 (Unsupported Media Type) is simply setting content negotiator in behaviors:
public function behaviors()
{
//...existing code...
$behaviors['contentNegotiator'] = [
'class' => \yii\filters\ContentNegotiator::className(),
'only' => ['index'],
'formatParam' => '_format',
'formats' => [
'text/event-stream' => \yii\web\Response::FORMAT_RAW,
],
];
//...existing code...
}
However, I was trying to make working example for you. But I got no luck as well.
What I did:
- Used https://github.com/odannyc/yii2-sse in Yii2
- Setup content negotiator for handling 'text/event-stream'
- Exempt CORS-pre-flight request for action method
- Used https://github.com/AlexGalays/EventSource in Angular2
When angular code calls EventSource
, the request hangs more than 45000 milliseconds and no results back.
If you succeed, could you share your code how you make it working?
from yii2-angular-boilerplate.
Hi, thanks for your full and informative answer for me. I got a step of app when have an error
Fetch API cannot load http://domain.my/sse/message. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
in my browser console. But so interesting that, status code is 200 OK and authorization is success)
I installed extension of EventSource wich use AlexGalays and add headers for authorization.
I added yii2-sse extension developed by odannyc.
Every time angular app trying to connect to my yii app and has previous error without any time delay.
I need your help with CORS.
And it will be done!)
from yii2-angular-boilerplate.
Hi @chrisleekr
I got success with my issue.
What I did:
-
Used https://github.com/odannyc/yii2-sse in Yii2
-
I installed extension of EventSource wich use AlexGalays in https://github.com/AlexGalays/EventSource and add headers for authorization.
eventSource = new EventSource('http://domain.my/sse/message', { headers: {'Authorization': 'Bearer ' + token}});
-
Add your code to behavior in my Controller
public function behaviors()
{
//...existing code...
$behaviors['contentNegotiator'] = [
'class' => \yii\filters\ContentNegotiator::className(),
'only' => ['index'],
'formatParam' => '_format',
'formats' => [
'text/event-stream' => \yii\web\Response::FORMAT_RAW,
],
];
//...existing code...
} -
Action in my Controller
$sse = Yii::$app->sse;
$sse->set('allow_cors', true);
$sse->set('keep_alive_time', 900);
$sse->addEventListener('message', new MessageEventHandler());
$sse->start();
$sse->flush();
Thanks.
from yii2-angular-boilerplate.
Related Issues (20)
- setup the app without docker HOT 7
- Windows installer HOT 1
- Error when running docker-compser up -d HOT 12
- 401 Unauthorized Error HOT 7
- ERROR: Service 'frontend' failed to build: Error parsing reference: HOT 6
- ERROR: Service 'api' failed to build: HOT 4
- Run App without docker HOT 1
- How to run project witout docker HOT 2
- Please Add PHPmyadmin HOT 2
- How to Open Yii2 Gii HOT 1
- Need brief explain about docker and nginx HOT 3
- Is possible to install without docker and nginx?using xampp and composer. HOT 2
- BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead. HOT 1
- BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead. HOT 1
- Login error - Username and Password cannot be blank. HOT 2
- pageSizeLimit HOT 2
- frontend and backend Dockerfile for production not working HOT 1
- API Bad Request HOT 2
- Error When `docker-compose up -d` HOT 5
- Error with " composer install --prefer-dist" when run docker-compose up -d
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-angular-boilerplate.