草庐IT

javascript - 未捕获的语法错误 : Identifier 'baseUrl' has already been declared

coder 2024-07-20 原文

我有一个使用 Firebase 托管部署的 Polymer webapp。

View 之间的路由有效,但错误页面处理无效。

我使用官方的 polymer-2-starter-kit 示例成功地在最小示例中重现了该问题:

https://fir-polymer-404-issue.firebaseapp.com/

例如,如果您打开以下网址,则不会显示错误页面:

https://fir-polymer-404-issue.firebaseapp.com/not-existing

相反,我收到以下错误:

my-not-existing.html:56 Uncaught SyntaxError: Identifier 'baseUrl' has already been declared
    at my-not-existing.html:56
(anonymous) @   my-not-existing.html:56

用于上一个示例的配置文件 firebase.json 在这里:

{
  "hosting": {
    "public": ".",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

我希望由 Polymer 进行错误页面处理。

请注意,由 polymer serve 提供的同一应用程序可以正常工作。

问题似乎出在 Firebase 托管配置上。所有流量都被重定向到 index.html,因此当 Polymer 加载一个不存在的页面时,Firebase 服务器返回一个 HTTP 200 响应。不幸的是,我不知道如何解决这个问题。

我尝试仅使用以下配置文件为非 404 响应创建重定向:

{
  "hosting": {
    "public": ".",
    "redirects": [
      {
        "source": "**",
        "destination": "/index.html",
        "type": 200
      }
    ]
  }
}

不幸的是,type 属性只能用于 3xx 代码:

Error: HTTP Error: 400, hosting.redirects[0].type is not one of enum values: 301,302,303,304,305,307,308

另请注意,自定义 404.html 文件为 placed at the root .

我看到的唯一解决方案是列出所有现有路由(每个文件),但它看起来很疯狂。

欢迎任何想法。

最佳答案

firebase 或 polymer 都无法处理您的 404 的原因page 是当你请求一个不存在的页面时,它不仅会返回状态代码 200但它也会返回 index 的 HTML页面,所以它会显示一些东西,虽然那东西真的没什么。

现在 polymer 的设置方式是在 src 中查找 View 文件夹,因此您只想在根目录而不是 src 中重写文件夹。所以改变你的firebase.json成为

{
    "hosting": {
        "public": ".",
        "rewrites": [{
            "source": "/*",
            "destination": "/index.html"
        }]
    }
}

*将意味着文件而不是子文件夹,如果您在地址栏中输入它,这将允许您的路由工作,但如果找不到该页面 404将由 polymer 路由处理。例如,我使用 polymer 入门包设置了一个 Firebase 应用程序。

https://testforsoissue.firebaseapp.com/view2

会工作,会带你到view2因为初始请求将被重写以返回 index.html 但对 /src/my-view2.html 的请求不会

而未定义的路由

https://testforsoissue.firebaseapp.com/not-existing

将抛出 404(在 polymer 中),因为初始请求将再次被重写以返回 index.html但是请求/src/my-not-existing.html不会并且会很乐意抛出 404!

附言错误原因'baseUrl' has already been declared'是因为页面使用了 index.html 两次,它在顶部声明了 baseUrl

编辑

如果你有子路径,你可以使用 firebase.json像这样

{
    "hosting": {
        "public": ".",
        "rewrites": [{
            "source": "!/src/*",
            "destination": "/index.html"
        }]
    }
}

关于javascript - 未捕获的语法错误 : Identifier 'baseUrl' has already been declared,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44420402/

有关javascript - 未捕获的语法错误 : Identifier 'baseUrl' has already been declared的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  3. ruby - 树顶语法无限循环 - 2

    我脑子里浮现出一些关于一种新编程语言的想法,所以我想我会尝试实现它。一位friend建议我尝试使用Treetop(Rubygem)来创建一个解析器。Treetop的文档很少,我以前从未做过这种事情。我的解析器表现得好像有一个无限循环,但没有堆栈跟踪;事实证明很难追踪到。有人可以指出入门级解析/AST指南的方向吗?我真的需要一些列出规则、常见用法等的东西来使用像Treetop这样的工具。我的语法分析器在GitHub上,以防有人希望帮助我改进它。class{initialize=lambda(name){receiver.name=name}greet=lambda{IO.puts("He

  4. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  5. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  6. ruby - 在 jRuby 中使用 'fork' 生成进程的替代方案? - 2

    在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',

  7. ruby - 主要 :Object when running build from sublime 的未定义方法 `require_relative' - 2

    我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby​​1.9+ 关于ruby-主要:Objectwhenrun

  8. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  9. ruby-on-rails - 使用 Sublime Text 3 突出显示 HTML 背景语法中的 ERB? - 2

    所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择

  10. ruby-on-rails - 新 Rails 项目 : 'bundle install' can't install rails in gemfile - 2

    我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="

随机推荐