question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Привет, я использую приложение на vue как тестовое, которое притворяется Алисой и отправляет запросы на навык.

Проблема в том, что post запросы из браузера не проходят, из-за отсутствия CORS заголовков в ответе yandex-dialogs-sdk.

Возможно ли сделать возможность указать заголовки, не меняя код sdk?

Я пока что прямо в alice.js listen вписал:

      app.use(function(req, res, next) {
        res.header("Access-Control-Allow-Origin", "*")
        res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
        next();
      })

Это помогло, но хочется по-нормальному сделать. Я вижу, что в alice.js есть middlewares, но они не используются, они предполагались как раз для таких случаев? Если да, могу отправить PR с доделкой этого функционала.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
popstascommented, Jun 12, 2018

По убыванию нормальности :

  1. Проще всего открыть доступ к экземпляру express, чтобы напрямую ему делать use, а мидлвари согласен, лучше оставить для ctx. По сути, если твой sdk выставляет правильные заголовки с точки зрения Яндекса, то сложно придумать, зачем еще это может понадобиться, кроме как для отключения CORS на время тестирования.

  2. Если правда других использований express не приходит в голову, можно сделать какой-нибудь флаг специально для этой фичи, например, alice.disableCORS().

  3. Можно вообще по умолчанию отключать CORS по условию process.env.NODE_ENV != 'production'

0reactions
fletcheristcommented, Aug 16, 2018

@popstas our new webhook server is implemented on pure http module to add CORS support you can easily use your own server, e.g express how to do CORS

  1. setup your own server
  2. use async handler
  3. enable cors by using package cors (npm install cors)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cross-Origin Resource Sharing (CORS) - MDN Web Docs
Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, ...
Read more >
Cross-origin resource sharing - Wikipedia
Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources on a web page to be requested from another domain outside the...
Read more >
CORS and the Access-Control-Allow-Origin response header
The CORS specification identifies a collection of protocol headers of which Access-Control-Allow-Origin is the most significant. This header is returned by a ...
Read more >
django-cors-headers - PyPI
Adding CORS headers allows your resources to be accessed on other domains. It's important you understand the implications before adding the headers, since...
Read more >
CORS Enabled - W3C Wiki
For IIS6 · Open Internet Information Service (IIS) Manager · Right click the site you want to enable CORS for and go to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found