0

What is wrong with my setup? have in mind I use express.

web.config file :

<handlers>
  <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>

<rewrite>
  <rules>
    <rule name="myapp">
      <match url="/*" />
      <action type="Rewrite" url="app.js" />
    </rule>
  </rules>
</rewrite>

and the app.js is as below :

var express = require('express');
var app = express();
var server = http.createServer(app).listen(process.env.port);

app.use(express.static(__dirname + '/pro/Public'));

app.get('/pro',function(req,res) {
 res.sendfile(__dirname + '/yoyo.html');
 res.end;
});

and the html has the classic layout like this:

<link rel="stylesheet" type="text/css" href="cssKtelVolouOsm.css">
<script type="text/javascript" src="javascriptKtelVolouOsm.js"></script>

and I get the following errors:

Failed to load resource: the server responded with a status of 404 (Not Found)      http://localhost/cssKtelVolouOsm.css 


Failed to load resource: the server responded with a status of 404 (Not Found)      http://localhost/javascriptKtelVolouOsm.js 
drizo
  • 267
  • 6
  • 14

1 Answers1

2

If those files actually exist under ./pro/Public then this is most likely caused by the use of relative URLs in your html. Try this instead.

<link rel="stylesheet" type="text/css" href="/cssKtelVolouOsm.css">
<script type="text/javascript" src="/javascriptKtelVolouOsm.js"></script>
Timothy Strimple
  • 22,920
  • 6
  • 69
  • 76
  • this answer doesn't seem to solve my problem I still get my error! :/ – drizo Dec 16 '14 at 10:50
  • Seems like I had another mistake I should not use './pro/Public' firstly I should use just './Public'. Still I don't get the static files,now the error gets projected differently,it says "GET http://localhost/cssvolos.css localhost/:7" and when I check the developers tools and check network tab at the .css and .js files it says type "text/html" instead of css or js. I think all the paths are correct,is there anything else that could be wrong? – drizo Dec 16 '14 at 12:02
  • Are you listening on port 80? What happens if you try to view that file directly? – Timothy Strimple Dec 16 '14 at 15:16
  • I listen to port process.env.port and when i try to access the file I get "Cannot GET /pro/public/file.css" . Any idea? – drizo Dec 16 '14 at 15:57
  • In my localhost setup everything works perfectly.What could be wrong with IIS setup? – drizo Dec 16 '14 at 21:29
  • What is the full get request? Is it still trying to access localhost in the URL? – Timothy Strimple Dec 16 '14 at 21:49
  • I am not sure what you mean. It is like this 'Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/public/javascriptvolos.js' in the console.Else, when I try to access the file straight with a url (http://localhost/pro/public/javascriptvolos.js) I get the following 'Cannot GET /pro/public/javascriptvolos.js'. – drizo Dec 16 '14 at 22:10
  • Your website is making requests to `localhost/pro/public/*`, of course it's not going to work when you publish it. How is your html being generated? You need to make sure you're not referencing localhost. – Timothy Strimple Dec 16 '14 at 22:17
  • I am a begineer and I don't really understand what you are saying friend. All of my code is above. I am not referencing anywhere localhost in my links,everything is relative URLs. Also,when I go to Network Tab in Google Chrome's Developers Tools I see that it requests the css and js as text/html. – drizo Dec 16 '14 at 22:21
  • When I run the nodejs server with Nodemon from command prompt everything goes as planned. When I use iisnode and make the necessary changes(code above) it fails. – drizo Dec 16 '14 at 22:24
  • OKKKKKKKKK I FIXED IT,thank god. Thanks friend your help was really great. I will post an answer later on I just changed the links in html from relative(the one you mention above) to almost fullpath, except for localhost(or domain name).It should be in the html part 'href=/pro/public/file.css' instead of '/file.css' or 'public.css' Change your answer if you want and I will take it as correct later on. – drizo Dec 16 '14 at 22:31
  • That's what I was trying to get at when I asked what the folder structure in your public folder was like. You made it sound like all the files were under the public folder directly. "What does the folder structure under ./pro/Public look like?" – Timothy Strimple Dec 16 '14 at 22:38
  • ok thanks Timothy, I am a beginner you see and I don't understand many things! – drizo Dec 17 '14 at 07:37