问题标签 [suave]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
798 浏览

visual-studio - 为什么我不能让 Suave 在 VS 2017 上工作?

我在https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Visual-F-Tools上看到了一个视频,其中创建了一个使用 Suave 的项目。我试图准确地遵循正在做的事情,但是我今天刚刚更新的 VS 2017 的安装表现完全不同。

首先,我完全按照视频中的方式安装了 Suave,它出现在我的参考文献中,介于mscorlib和之间System,就像在视频中一样。

然后视频显示以下代码:

此时 VS 2017 在视频中建议“Open Suave”,因为无法识别 startWebServer。我在编辑器中的文件中复制了相同的代码Program.fs。出现错误消息“未定义值或构造函数'startWebServer'”但当光标悬停在左侧黄色区域时没有任何建议。(也许是因为我使用的是社区版?)

无论如何,我添加open Suave到代码中,所以我有:

此时,我在 Suave 下看到一个红色波浪线,并显示错误消息“未定义命名空间或模块‘Suave’。”

如果我在解决方案资源管理器中右键单击 Suave,然后选择“Send to Interactive”,那么我可以Suave在 F# Interactive 中打开。

我可以毫无问题地安装和使用 Deedle 等其他软件包。

关于什么是错的任何想法?

0 投票
1 回答
125 浏览

f# - 添加 Suave - 打开声明不起作用

我通过 NuGet 将 Suave.io 添加到我的项目中 - 到目前为止是空的 - 没关系。但是没有任何open Suave声明产生“未定义命名空间或模块“Suave”。” 以下在脚本文件中有效:

0 投票
1 回答
260 浏览

f# - 在 Suave 中映射 json 输入但不输出

Suave.Json.mapJson将输入 JSON 映射到函数中的对象,然后将函数的输出映射到 JSON。

问题是我对它映射到我的函数的方式很满意,但我需要返回一个 json 字符串响应,而不是让我的输出为我温和地序列化为 JSON。我怎样才能做到这一点?

目前我正在将我的输出序列化两次。到目前为止我的代码:

0 投票
2 回答
717 浏览

f# - 在 Suave 中允许多个带有 CORS 的标头

我正在尝试让我的 Suave API 接受 CORS 请求。我在这里遵循了这个片段:

http://www.fssnip.net/mL/title/CORS-response-with-Suave

我将在这里重新创建:

但是现在我有需要传入令牌的端点,并且由于缺少 CORS 中允许的标头,这些端点正在给出错误。我的令牌头只是“令牌”,所以我尝试了两件事,但都没有解决问题。

尝试#1

这返回了一个错误,说content-type不再接受 - 这似乎意味着最后一个setHeader覆盖了第一个,当您在此处查看源代码时:https ://github.com/SuaveIO/suave/blob/master/src/Suave .Tests/HttpWriters.fs在第 113 行,有一个测试对我来说意味着这是所需的行为。

尝试#2

根据对这个问题的回答:How to set a Json response in suave webpart,我尝试通过逗号分隔的列表设置两个标题:

但这随后给出了一个错误,表明 CORS 完全失败了:

同样基于同样的问题,我尝试了以下方法:

这给出了这样的回应:Request header field token is not allowed by Access-Control-Allow-Headers in preflight response.

那么,如何在 Suave 的 CORS 请求中允许任意数量的标头?

编辑

尝试#3

我用addHeader而不是setHeader

现在是说...No 'Access-Control-Allow-Origin' header is present on the requested resource.

如果我先将其更改setHeaderaddHeader,我仍然会得到相同的响应。

使固定

完成了这项工作 - 在此之后,发送的内容出现了问题,但 CORS 本身就没有其他问题了。

0 投票
2 回答
82 浏览

f# - 在 Suave 中使用非拉丁字符

我想在Suave中使用非拉丁符号,例如西里尔字母,但得到奇怪的结果

MCVE

结果

在此处输入图像描述

所以,问题是 - 如何解决它?

0 投票
0 回答
323 浏览

f# - Azure AD、Angular 2 和预检出现问题无效(重定向)

现在我没有很好地集成 Angular 2 和 Azure AD。

重现错误的步骤:

  1. 我创建了一个 Angular 2 前端 Web API(suave.io) 并部署了 Azure
  2. 我已经在网站和 Web API 上设置了 Azure AD
  3. 关注了这篇文章:

https://blogs.msdn.microsoft.com/premier_developer/2017/04/26/using-adal-with-angular2/

  1. 我得到了持有者 Azure AD 令牌(很棒)
  2. 然后我调用Web API,我得到了

XMLHttpRequest 无法加载https://#### /groups/。预检响应无效(重定向) 这与此问题有关。

https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests

我的 Angular 2 代码是这样的:

此调用删除授权令牌并发送选项调用。我相信请求失败是因为没有身份验证标头,并且 AD 在它到达 Web API 之前拒绝了它。

这是现在从 chome 发送的请求:

我的网络配置有:

我能做些什么?这对我来说是目前的一个主要问题。我猜将来会有越来越多的人使用 Angular 2 和 AD 集成。任何提示或想法将不胜感激。

0 投票
1 回答
109 浏览

rest - 嵌套 Suave WebPart

我第一次在 Suave 周围玩,显然有些东西我不明白。我想要实现的是实现一个简单的 Rest API:

  • 用户可以获得有关金融工具的信息
  • 此外,每一种工具都有一个价格清单

现在为简单起见,我只关注 GET 方法。

非常基本的一段代码在这里:

当我以这种方式定义 WebPart 时:

然后一切正常。我想知道是否有嵌套 webpart 的方法,例如:

另外 - 当我正在学习 RestAPIs 时,我的推理可能存在差距。我认为以这种方式嵌套价格端点清楚地表明价格被视为一种工具的属性(如果我错了,请随时纠正我)。

0 投票
1 回答
276 浏览

powershell - client is waiting forever for remote server to return a webpage

I have an application with a server written in F# and serve web files using suave. I remote login using powershell into another machine in the network to run the application (The application is also in one of the network drives). I do that because that machine have access to third party APIs needed for the server. Now when I do [IPAddress_Of_Remote_Machine]/[html_file] or [name_of_pc]/[html_file] then chrome is waiting forever and doesn't ever return the webpage. This wasn't happening before and I ran into this problem recently. I opened a different port and used it instead of the default one 80. This made things work but the problem keeps showing up after a couple of days. I don't think it's a firewall issue but I'm clueless to why this is happening.

When running netstat -an, this is what I get (I hid the IP address):

enter image description here

As you can see all of the connections are either in CLOSE_WAIT or ESTABLISHED but not LISTENING. All of these TCP connections is probably because I have PhantomJS and two other APIs running in the application as well. However the loop back address is also open on the same port 5959: enter image description here

I'm not sure what is difference between these two but when using PortQryUI to query the remote server it returns a success!

enter image description here

I have already made an inbound rule for port 5959 on the server so it should be allowed. The web page is stuck at Waiting for [name_of_pc]. Also, sometimes this problem disappears and everything works fine.

What is the potential problem behind this? Why would this happen all of a sudden?

UPDATE:

I re-ran the application today and it's working correctly. It could be that something is dynamically set within the firewall? Not really sure what is going on. The machine I'm running the server on has a bunch of applications running on it as well so maybe there is an external process that is affecting it?

I made a hello world app with Suave and deployed it on the network drive to test if it's going to work. I opened inbound rule for port 6001 enter image description here

Then I ran the app: enter image description here

However, it's still not working and this time it says the site cannot be reached when I do: http://[name_of_pc]:6001.

enter image description here

0 投票
1 回答
54 浏览

f# - F#:无法使用 Suave.Types 构建脚本

尝试使用 Thomas Petriek 的构建脚本:https ://github.com/tpetricek/suave-xplat-g​​ettingstarted/blob/master/build.fsx

在打开的 Suave.Types 中未定义命名空间类型的错误。

这是一些后来被弃用的命名空间吗?

0 投票
1 回答
162 浏览

f# - 温和的实验形式选择输入

我正在扩展http://vgaltes.com/suave/forms-with-suave-experimental-and-suave-forms / 上的教程以支持 HTML 选择输入/下拉列表。

问题是它divAttr需要一个 Xml 类型,但Suave.Form.input返回一个Node. 有谁知道如何解决这个问题或有一个如何做一个可以添加到的选择输入的例子divAttr

我从 Suave Music Store 的书中看过一个如何做到这一点的例子。但这似乎已经过时,并且与最新版本的 Suave 无关。

我正在运行 Suave & Suave.Experimental 2.1.0。

谢谢!