Clark
Clark

Reputation: 2678

How can I use parent paths with a typescript project with IIS express?

So I have this:

/projectA/index.html

And for the sake only for testing I want to have this in index.html

<script src="../projectB/somefile.foo"></script>

Of course, when I run visual studio, my foo file cannot be found because it is above the project "root".

Is there any way to allow IIS to gain access to projectB?

I am using TypeScript with Visual Studio 2013.

Note: I did google this, but I find asp stuff. As far as I am aware, this is not relevant to me?

Thanks!

Upvotes: 1

Views: 417

Answers (1)

David Sherret
David Sherret

Reputation: 106650

The browser is trying to access the file at ../projectB/somefile.foo relative to where the current page is. Ask yourself this question, if you were using a web browser, how would you navigate to ../projectB/somefile.foo?

I'm going to make a bit of an assumption and guess that index.html is at a url that looks something like this:

http://localhost:55685/index.html

Now, as you pointed out, it doesn't really make sense to go up a directory using ../ when you are already in the root directory.

You have two options I can think of right now. One is that in the project's properties, on the Web tab you can configure a Project Url for projectB. For example http://localhost:55685/projectB. Then in your app do this:

<script src="http://localhost:55685/projectB/somefile.foo"></script>

You'll have to do some additional configuration if you ever deploy your application, but it's a solution that works if you just need it for development.

Another option is to copy the script files from projectB into projectA. I would recommend this, especially if projectB isn't going to be deployed somewhere. If you are trying to access some TypeScript files, you can use a method similar to what is outlined in this other answer. Otherwise, just make a build event that runs a script to copy all your script files into projectA. After that, reference the script files you need at the location you copied them to in projectA.

Upvotes: 3

Related Questions