0

I cannot figure out what I am doing wrong.

Here's my directory structure:

+projectName
  +node_modules
  +public
    +stylesheets
      -style.css
  +routes
    -index.js
  +views
    +partials
      -footer.hbs
      -header.hbs
    -index.hbs
    -results.hbs
  -.gitignore
  -app.js
  -package-lock.json
  -package.json
  -web.config

web.config file is as follows:

<configuration>
<system.webServer>

    <!-- indicates that the app.js file is a node.js application
    to be handled by the iisnode module -->

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

    <rewrite>
        <rules>

            <rule name="StaticContent">  
                <action type="Rewrite" url="public{{REQUEST_URI}}" logRewrittenUrl="true" />
            </rule>

            <rule name="DynamicContent" patternSyntax="ECMAScript">
                <conditions>
                    <add input="{{REQUEST_FILENAME}}" matchType="IsFile" negate="True" />
                </conditions>
                <action type="Rewrite" url="app.js" logRewrittenUrl="true" />
            </rule>

        </rules>
    </rewrite>

</system.webServer>
</configuration>

app.js is as follows:

var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var hbs = require('hbs');

var index = require('./routes/index');
var compression = require('compression');
var helmet = require('helmet');

var app = express();

app.use(helmet());

// view engine setup
hbs.registerPartials(__dirname + '/views/partials');
app.set('view engine', 'hbs');
app.set('views', path.join(__dirname, 'views'));
hbs.registerHelper('getCurrentYear', ()=> {
    return new Date().getFullYear();
});

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());

app.use(compression()); // Compress all routes

app.use(express.static(path.join(__dirname, 'public')));

app.use('/', index);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

app.listen(process.env.PORT || 3000);

header.hbs contained in views/partials contains the following:

<link rel="stylesheet" type="text/css" href="/stylesheets/style.css">

When I run on localhost:3000, there are no issues. When I run on IIS Server via IISNode module, I receive the follow error message in the console of Chrome's Dev Tools:

Failed to load resource: the server responded with a status of 404 (Not Found) style.css

I feel like I am missing something that is painfully obvious.

mjvinti
  • 1
  • 3
  • Here's my static rule in my web.config ` ` – gh0st Apr 17 '18 at 15:47
  • @mjvinti Did you figure this out? I am having the same issue. – NorCalKnockOut May 18 '18 at 22:53
  • @gh0st could you post your entire web.config? – NorCalKnockOut May 18 '18 at 22:57
  • @NorCalKnockOut https://pastebin.com/GXHM3KFu althought I don't think this part is going to help you. I think what actually solved my problem was correctly calling `app.use(express.static(...))` – gh0st May 19 '18 at 02:04
  • @gh0st Can you elaborate on this, please. I'm having this same issue with my iisnode. What do you mean by "correctly calling app.use..."? – ChiragMS Dec 15 '19 at 05:22
  • @ChiragMS, try `console.write()` on what you would pass to `express.static()` to help you narrow down what exactly is getting passed to it – gh0st Dec 16 '19 at 17:11

0 Answers0