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.