Webstorm 上下文文件夹总是包含在 url 路径中? [英] Webstorm Context Folder always included on url path?

查看:46
本文介绍了Webstorm 上下文文件夹总是包含在 url 路径中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的理解,WebStorm 有上下文根的概念(基本上是您项目的根,用于源目的)和资源根文件夹,从中可以相对解析网络请求.

Based on my understanding WebStorm has the concept of context Root ( basically the root of your project for source purposes) and Resource Roots folder(s) from which web requests can be resolved relative to.

我有一个类似的项目结构

I've got a project structure like

Projects (Context Root)
      |
      MyProject  (ResourceRoot)
         |--- html
         |----css
         |----images

我想像这样访问我的 html 文件 http://localhost:34343/html/index.html

I'd like to access my html files like so http://localhost:34343/html/index.html

然而这是不可能的.我可以访问文件的唯一方法是当项目"上下文根构成我的 url 的一部分时.例如 http://localhost:34343/项目/html/index.html

however that's not possible. The only way I can access files is when the 'Projects' context root forms part of my url. e.g http://localhost:34343/Projects/html/index.html

(请注意,resourceroot 似乎在某种程度上有效,因为我可以省略路径的MyProject"部分.

(note that the resourceroot seems to be working to some extent as a I can omit the 'MyProject' part of the path.

我有一些带有绝对引用的 css,它们想要访问/images,当必须包含上下文根时会中断.据我所知,将上下文根向下"移动一个级别不会有帮助,因为它需要在路径上使用MyProject".

I've got some css with absolute references that want to access /images which break when the context root has to be included. As far as I can tell moving the Context root 'down' a level isn't going to help as it will require 'MyProject' on the path.

我猜我可能会强制它使用像 apache 这样的东西,这样我可以更好地控制 url 解析,但理想情况下我会使用 IDE 中的内置服务器.

I'm guessing I can probably force it to use something like apache where I can get more control of url resolution, but Ideally I'd use the built in server from the IDE.

推荐答案

http://localhost:63342/html/index.html -- 你不能有这种 URL内置网络服务器 .. 因为 IDE 不知道要服务哪个项目(因为它适用于您的所有项目,不仅当前打开).

http://localhost:63342/html/index.html -- you cannot have this kind of URL with built-in web server .. as IDE does not know what project to serve (as it works for ALL your projects a not only currently opened).

当使用内置网络服务器时,URL 必须有一些提示 (PROJECT_NAME) 来告知要服务的项目(从哪里获取文件).

When built-in web server is in use, the URL has to have some hint (PROJECT_NAME) that would tell what project to serve (where to take files from).

内置网络服务器支持 2 种 URL(它们都将提供相同的文件):

Built-in web server supports 2 kind of URLs (both of them will serve the same file):

http://localhost:63342/PROJECT_NAME/index.html
http://PROJECT_NAME:63342/index.html

如果您对第二个网址感到满意,那么您必须执行以下步骤:

If you happy with 2nd URL, then you will have to do these steps:

  1. 创建部署条目(设置/首选项 | 构建、执行、部署 | 部署)并将其标记为该项目的默认值.在 IDE 中打开页面时将使用此处定义的 URL (http://PROJECT_NAME:63342/).

  1. Create Deployment entry (Settings/Preferences | Build, Execution, Deployment | Deployment) and mark it as Default for this project. The URL defined there (http://PROJECT_NAME:63342/) will be used when opening pages from within IDE.

如果您想使用在浏览器中打开功能,这是必需的,否则您可以安全地跳过它.

This is required if you want to use Open in Browser functionality, otherwise you may safely skip it.

在您的 hosts 文件(或您的本地 DNS 服务器,如果有的话)中定义一个条目,将 PROJECT_NAME 指向您的 IP.例如(对于 hosts 文件):127.0.0.1 PROJECT_NAME.

In your hosts file (or your local DNS server, if you have one) define an entry that would point PROJECT_NAME to your IP. For example (for hosts file): 127.0.0.1 PROJECT_NAME.

这篇关于Webstorm 上下文文件夹总是包含在 url 路径中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆