小编lol*_*101的帖子

socket.io, 'Access-Control-Allow-Origin' 错误

我已经设置了一个带有套接字 io 转动的节点服务器,并尝试通过另一台服务器连接到它。但是,不同计算机上的某些浏览器会出现此错误并使其始终重新连接:

XMLHttpRequest 无法加载https://serverDomain.net:3000/socket.io/?EIO=3&transport=polling&t=Lo_SdiU。当请求的凭据模式为“包含”时,响应中“Access-Control-Allow-Origin”标头的值不得为通配符“*”。因此,不允许访问Origin ' https://www.differentServerDomain.fr '。XMLHttpRequest 发起的请求的凭证模式由 withCredentials 属性控制。

我的js配置:

var port = 3000;
var fs = require('fs');
var https = require('https');
var express = require('express');
var app = express();

var options = {
    key: fs.readFileSync('/etc/letsencrypt/live/devpeter.net/privkey.pem'),
    cert: fs.readFileSync('/etc/letsencrypt/live/devpeter.net/fullchain.pem')
};
var server = https.createServer(options, app);
var io = require('socket.io')(server);
io.origins('https://www.differentServerDomain.fr:* https://www.differentServerDomain.fr/wp-admin/index.php:*');

// start of server
server.listen(port, function(){
    console.log('listening on *: '+ port + "\n");
});
Run Code Online (Sandbox Code Playgroud)

我正在使用 node 8.0 和 socket io 2.2,您的帮助将不胜感激。

编辑:这是客户端代码:

<script src="https://serverDomain.net:3000/socket.io/socket.io.js"></script>
<script>
   var …
Run Code Online (Sandbox Code Playgroud)

javascript node.js cors socket.io

13
推荐指数
7
解决办法
4万
查看次数

更改 ag-grid 上的页面和缓存块大小会导致无限加载项目

我希望使用 ag-grid 的“服务器端”模式重新获取每个页面的数据。为此,我使 maxBlocksInCache 1 和 cacheBlockSize 等于每页的项目数。直到这里它工作正常。

现在,当我更改每页的项目数时,网格开始通过获取数据自行循环。我假设这是因为 cacheBlockSize 在重新获取行(永远不会完成)后不可更改或更改。

现在我试图将缓存作为输入而不是 agGridOption ,但它什么也没改变。

<select #paginationSelect (change)="onPageSizeChanged(paginationSelect.value)" [(ngModel)]="itemsPerPage">
    <option [value]="item">2</option>
    <option [value]="item">10</option>
</select>
<ag-grid-angular
        [gridOptions]="gridOptions"
        [cacheBlockSize]="itemsPerPage"
        style="width: 100%; height: 250px;">
</ag-grid-angular>
Run Code Online (Sandbox Code Playgroud)
this.gridOptions = {
            ...
            rowModelType: 'serverSide',
            pagination: true,
            paginationPageSize: this.itemsPerPage, // itemsPerPage is a class attribute attached to a select element using ngModel.
            maxBlocksInCache: 1,
            ...
}

// function called on change of select element value representing the number of items to display per page
onPageSizeChanged(newPageSize) {
        this.gridApi.paginationSetPageSize(newPageSize);
    } …
Run Code Online (Sandbox Code Playgroud)

pagination server-side typescript angular ag-grid-angular

9
推荐指数
1
解决办法
2764
查看次数

如何只生成API的接口?

我试图仅使用 OpenApi 及其 maven 插件openapi-generator-maven-plugin生成接口,但它也生成我不想要/不需要的完整服务。

现在我找到了withInterfaces属性,但当设置为 true 时,它​​还会生成 API 服务。因此它会生成我想要的服务,但也会生成我不想要的服务。

这是我的 pom 配置:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>3.3.4</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${openAPIContractsDirectory}/swagger.json</inputSpec>
                <generatorName>typescript-angular</generatorName>
                <output>${openAPIOutputDirectory}</output>
                <configOptions>
                    <ngVersion>7.2.11</ngVersion>
                    <withInterfaces>true</withInterfaces>
                </configOptions>
                <generateApiTests>false</generateApiTests>
                <generateApiDocumentation>false</generateApiDocumentation>
                <generateModelTests>false</generateModelTests>
                <generateModelDocumentation>false</generateModelDocumentation>
                <supportingFilesToGenerate>variables.ts,configuration.ts,encoder.ts</supportingFilesToGenerate>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我想要的是模型、pom 中描述的一些支持文件,以及API 接口(不是完整的服务)

有人知道如何做到这一点吗?

typescript openapi angular openapi-generator

8
推荐指数
1
解决办法
7608
查看次数

有 mat-autocomplete 不是替换而是增加价值

我知道onSelectionChange()通过 mat-autocomplete 的 mat-option 我可以在选择一个选项时做一些事情,但我想要的是自动完成将 mat-option 的值添加到输入而不是替换其内容。

例子:

  • 输入:“你好”
  • 单击垫选项“世界”
  • 输入:“你好世界”

我如何在不保留表单值的标签并存储其先前值并将其放回原处的情况下完成此操作(因为这似乎是一个糟糕的解决方法)?

<mat-form-field class="w-100">
   <textarea [matAutocomplete]="auto" [value]="hello" matInput></textarea>
   <mat-autocomplete #auto="matAutocomplete" >
      <mat-option [value]="world">
         world
      </mat-option>
   </mat-autocomplete>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

typescript angular-material angular

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

如何在不重新渲染的情况下更新我的 mat-tree?

我的 mat 树重绘使用 BehaviorSubject 在数据源数据更改时初始化自己。

我正在使用一个 observable,我不时更新表单以更新由 FlatTreeControl 生成的树数据。

该代码非常基本且易于理解,因此我没有看到问题。

我尝试在 stackBlitz 上使用简化版的 angular flat tree 示例:https ://stackblitz.com/angular/rlqvokgplrko ? file = app%2Ftree-checklist-example.ts

这是我的版本:https : //stackblitz.com/edit/create-iq2meg

我期望的是,就像在官方 mat-tree 示例中一样,数据是动态更新的,而不必每次都重新绘制整个树并使其折叠在我身上。

treeview asynchronous angular-material angular

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