小编Wer*_*ner的帖子

FastAPI 变量查询参数

我正在编写一个 Fast API 服务器,它接受请求,检查用户是否获得授权,然后如果成功则将他们重定向到另一个 url。

我需要携带 URL 参数,例如

http://localhost:80/data/?param1=val1¶m2=val2 应该重定向到 http://some.other.api/?param1=val1¶m2=val2,从而保留之前分配的参数。

有些参数不是我控制的,随时可能改变。

我怎样才能做到这一点?

代码:

from fastapi import FastAPI
from starlette.responses import RedirectResponse

app = FastAPI()

@app.get("/data/")
async def api_data():
    params = '' # I need this value
    url = f'http://some.other.api/{params}'
    response = RedirectResponse(url=url)
    return response

Run Code Online (Sandbox Code Playgroud)

python fastapi

7
推荐指数
3
解决办法
7184
查看次数

MS SQL Server Docker 数据位置

我正在使用mcr.microsoft.com/mssql/server:2019-latest容器,并希望挂载其数据目录,以便在服务器出现故障时数据不会丢失。

数据目录位于里面的什么位置?文档根本没有提到这一点。

sql-server docker sql-server-2019

6
推荐指数
1
解决办法
1万
查看次数

FastAPI RedirectResponse 自定义标头

基于我之前的问题,我现在需要在响应中添加一个标头。

根据文档,我可以简单地将标题和另一个属性添加到RedirectResponse对象中。

当我对此进行测试时,它似乎没有携带标头值。

根据这篇文章,不可能为重定向请求设置标头。所以,而不是重定向,也许我应该尝试其他方法?

有任何想法吗?

from fastapi import FastAPI, Request
from starlette.responses import RedirectResponse

app = FastAPI()

@app.get("/data/")
async def api_data(request: Request):
    params = str(request.query_params)
    url = f'http://some.other.api/{params}'
    headers = {'Authorization': "some_long_key"}
    response = RedirectResponse(url=url, headers=headers)
    return response
Run Code Online (Sandbox Code Playgroud)

python fastapi

5
推荐指数
1
解决办法
6077
查看次数

Rust 使用 Postgres JSON 属性:无法在 Rust 类型 `alloc::string::String` 和 Postgres 类型 `jsonb` 之间进行转换

目前我可以使用以下代码,但我不想在 postgres 查询中将 JSON 转换为文本,因为它会增加延迟。

async fn filter_data(min : f32, max : f32, pool: &Pool) -> Result<String, PoolError> {
    let client: Client = pool.get().await?;
    let sql = format!("select \"json\"::TEXT from get_data({}, {})", min, max);
    let stmt = client.prepare(&sql).await?;
    let rows = client.query(&stmt, &[]).await?;
    Ok(rows[0].get(0))
}
Run Code Online (Sandbox Code Playgroud)

如果我不将 JSON 转换为文本,则会收到以下错误:

error retrieving column 0: error deserializing column 0: cannot convert between the Rust type `alloc::string::String` and the Postgres type `jsonb`
Run Code Online (Sandbox Code Playgroud)

可以使用什么类型以便我返回该 json 值而不将其转换为文本?

postgresql json rust rust-tokio

4
推荐指数
1
解决办法
3898
查看次数

Nginx:删除单个查询字符串参数

我有一个服务器,它返回一个包含 API 密钥的 301 HTTP 重定向 URL。重定向命中 Nginx,在那里我需要添加一个Authorization包含 API 密钥值的HTTP 标头。然后我想从发送的查询参数中删除 API 密钥

我需要翻译/google/?search=abcde&apikey=1234&version=1/google/?search=abcde&version=1

代码

location /google/ {
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    Host                $http_host;
    proxy_set_header    Authorization       "Bearer $arg_apikey";
    proxy_pass          https://google.com/;
}
Run Code Online (Sandbox Code Playgroud)

我尝试了以下操作,但不起作用: 删除 nginx 重写中的参数

location /google/ {
    if ($query_string ~ "^(.*)apikey=(.*)$") {
       rewrite ^(.*)$ $uri? permanent;
    }
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    Host                $http_host;
    proxy_set_header    Authorization       "Bearer $arg_apikey";
    proxy_pass          https://google.com/;
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激!

nginx nginx-reverse-proxy

4
推荐指数
1
解决办法
1114
查看次数

如何从HTML源刷新/重新加载DataTable

我正在使用BackboneJS用多个数据源填充表。您无需了解Backbone即可解决此问题,因为该问题主要是DataTables问题。

我在首次呈现“集合视图”时初始化我的数据表。

我的问题是我不知道如何在每个ajax请求之后告诉DataTables如何从DOM重新加载其数据。关于如何执行此操作的任何想法?

另一个示例是在为每一行加载一些数据然后进行相应更新时(由主干视图完成)。但是我需要让Datatables知道DOM表已更改

更改表的示例:

<table>
  <thead>...</thead>
  <tbody>
    <tr>
        <td>Some Data</td>
        <td>Some Data2</td>
        <td>Loading...</td>
    </tr>
    ...
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

至:

<table>
  <thead>...</thead>
  <tbody>
    <tr>
        <td>Some Data</td>
        <td>Some Data2</td>
        <td data-order="5" data-search="5"><span class="some_classes">5</span></td>
   </tr>
      ...
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激。

html javascript datatables backbone.js backbone-views

2
推荐指数
1
解决办法
8385
查看次数