简体   繁体   English

Angular 2中的Fetch.js抱怨CORS请求

[英]Fetch.js in Angular 2 complains of a CORS request

I'm vaguely following the quickstart tutorial to set up and use angular 2 in an application that communicates with an expressjs backend. 我模糊地按照快速入门教程设置并在与expressjs后端通信的应用程序中使用angular 2。 I've encounted a few dependency issues and resolved most of them, but I'm stuck. 我已经解决了一些依赖问题并解决了大部分依赖问题,但我陷入困境。 The error I'm encountering is: 我遇到的错误是:

Fetch API cannot load npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js. URL scheme must be "http" or "https" for CORS request.

My systemjs.config.js file is verbatim what is specified in their quickstart. 我的systemjs.config.js文件是他们的快速入门中指定的文字。

(function(global) {
    System.config({
        paths: {
            'npm': 'node_modules/'
        },

        map: {
            app: 'app',

            // angular bundles
            '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
            '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
            '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
            '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
            '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
            '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
            '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
            '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

            // other libraries
            'rxjs':                      'npm:rxjs',
            'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
        },

        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: {
                defaultExtension: 'js'
            },
            rxjs: {
                defaultExtension: 'js'
            }
        }
    });
})(this);

A lot of the issues I was encountering were resolved by specifying the correct static paths in my expressjs script. 我遇到的很多问题都是通过在expressjs脚本中指定正确的静态路径来解决的。 What confuses me is why only that file, (platform-browser-dynamic.umd.js) is considered a CORS request. 令我困惑的是为什么只有那个文件(platform-b​​rowser-dynamic.umd.js)被认为是一个CORS请求。 I've confirmed it exists in the directory specified, so that isn't the issue. 我已经确认它存在于指定的目录中,所以这不是问题。 Does anyone have any insight on this? 有没有人对此有任何见解? (most of the clientside source is verbatim from their quickstart for now, if you think it's relevant, just ask and I'll post it). (目前大多数客户端来源都是他们的快速入门,如果你认为它是相关的,只要问一下,我就会发布它)。

Troubleshoot for 4 hours, get fed up, post question, find answer moments later. 排除故障4小时,厌倦了,发布问题,稍后找到答案。

Twas a typo. 这是一个错字。 Apparently, if you specify a script whose path hasn't been specified and is an otherwise unknown protocol, it will attempt to treat it as a CORS request. 显然,如果您指定的路径尚未指定并且是未知协议的脚本,它将尝试将其视为CORS请求。

What I had: 我有什么:

path: {
    'npm': 'node_modules/'
}

What it should be: 应该是什么:

path: {
    'npm:': 'node_modules/'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM