我正在尝试使用本地计算机上的iisnode在IIS上部署我的MEAN框架应用程序。
我的api调用在IIS上托管后正在运行,但Web应用程序页面未加载,因为它无法加载与Web应用程序相关的必需的css和js文件。
我的 server.js 包含以下代码: -
var express = require('express');
var app = express();
var http = require('http').Server(app);
var path = require('path');
var mongoOps = require('./MongoOperations.js');
var googleAuthOps = require('./passport_google.js');
var bodyparser = require('body-parser');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var cookieParser = require('cookie-parser');
var session = require('express-session');
exports.io = require('socket.io')(http);
var port = process.env.port || 1337;
app.use(bodyparser.json()); // for parsing application/json
app.use(bodyparser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(session({ secret: 'this is the secret' }));//, resave: true, saveUninitialized: true }));
app.use(cookieParser());
app.use(passport.initialize());
app.use(passport.session());
console.log("In Express top");
app.use(express.static(__dirname + '/views/src'));
console.log("In Express 11");
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function (user, done) {
done(null, user);
});
app.post("/login", passport.authenticate('local'), function (req, res) {
console.log('user' + req.user);
var user = req.user;
console.log(user);
res.json(user);
});
app.get('/loggedin', function (req, res) {
res.send(req.isAuthenticated() ? req.user : '0');
});
app.post('/logout', function (req, res) {
req.logout();
res.redirect('/login');
//res.send(200);
});
app.get('/auth/google', passport.authenticate('google',
{
hd: 'gslab.com',
scope: ['https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email']
}),
function (req, res) { } // this never gets called
);
app.get('/auth/google/callback', passport.authenticate('google',
{ successRedirect: '/#/dashboard', failureRedirect: '/#/login' }//this may change when website published to logout from all google services https://accounts.google.com/logout
));
app.use(function (req, res, next) {
if (!req.user)
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
next();
});
var auth = function (req, res, next) {
if (!req.isAuthenticated())
res.send(401);
else
next();
};
app.get('/', function (request, response) {
response.sendfile("views/src/index.html");
});
app.get('/idp1/api/idcnt', mongoOps.fetchIdeaCount);
app.get('/idp1/api/reclimit/:p_num', mongoOps.fetch);
app.post('/idp1/api/results', mongoOps.add);
//app.put('/idp1/api/results/:resultId', mongoOps.modify); //for later use
app.put('/idp1/api/results/:resultId', mongoOps.modify2);
app.get('/idp1/api/myreclimit/:uid/:pNum', mongoOps.fetchMyIdeas);
app.get('/idp1/api/myidcnt/:uid', mongoOps.fetchMyIdeaCount);
app.put('/idp1/api/updateidea/:iid', mongoOps.modifyIdea);
//Question master related routes
app.post('/idp1/api/question', mongoOps.upsertQuestion);
app.get('/idp1/api/question', mongoOps.getAllQuestion);
app.get('/idp1/api/question/:questionId', mongoOps.getQuestion);
app.delete('/idp1/api/question/:questionId', mongoOps.deleteQuestion);
//Role master related routes
app.post('/idp1/api/role', mongoOps.upsertRole);
app.get('/idp1/api/role', mongoOps.getAllRole);
app.get('/idp1/api/role/:roleId', mongoOps.getRole);
app.delete('/idp1/api/role/:roleId', mongoOps.deleteRole);
//Access rights related routes
app.get('/idp1/api/accessright', mongoOps.getAllAccessRight);
//Technology stuff
app.get('/idp1/api/techResults', mongoOps.fetchTechnology);
app.post('/idp1/api/techResults', mongoOps.addTechnology);
app.delete('/idp1/api/techResults/:id', mongoOps.delTechnology);
app.put('/idp1/api/techResults/:id', mongoOps.editTechnology);
app.get('/idp1/api/techResults/:id', mongoOps.getData);
app.post('/idp1/api/techResults', mongoOps.editTechnology);
app.get('/idp1/api/catresults', mongoOps.fetchCat);
app.get('/idp1/api/commentspnid/:iid/:pn', mongoOps.fetchCom2); //to fetch comments after pagination
app.get('/idp1/api/comments/count/:ideaId', mongoOps.fetchComCount); //to fetch comments count
if (app.post('/idp1/api/practice', mongoOps.addPractice)) { console.log("in practice post if"); }
app.put('/idp1/api/comments', mongoOps.modifyCom);
app.put('/idp1/api/updatecommentsNotify/:ideaId', mongoOps.resetCommentNotificationCount)
app.get('/idp1/api/getUserId/:userEmail', mongoOps.fetchUserData);
app.get('/idp1/api/userdetails/:userEmail', mongoOps.fetchUserData);
app.put('/idp1/api/userdetailstoupdate/:userId', mongoOps.updateUserData);
app.post('/idp1/api/userdetails', mongoOps.addUser);
app.post('/idp1/api/upsert_category', mongoOps.upsertCategory);
app.get('/idp1/api/fetch_categories', mongoOps.fetchCat);
app.get('/idp1/api/fetch_category/:categoryId', mongoOps.getSingleCat);
app.put('/idp1/api/delete_category/:categoryId/:userId', mongoOps.deleteCategory);
app.use('/idp11', express.static(path.join(__dirname, 'views/src/components')));
app.use('/idp2', express.static(path.join(__dirname, 'views/dist/js')));
app.use('/idp3', express.static(path.join(__dirname, 'views/src/img')));
app.use('/idp4', express.static(path.join(__dirname, 'views/src/templates')));
app.use('/idp5', express.static(path.join(__dirname, 'views/src/js')));
app.use('/idp6', express.static(path.join(__dirname, 'views/src')));
http.listen(port);
web.config文件如下: -
<?xml version="1.0" encoding="utf-8"?>
<!--
This configuration file is required if iisnode is used to run node processes behind
IIS or IIS Express. For more information, visit:
https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->
<configuration>
<system.webServer>
<!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>
<!-- All other URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>
<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />
<!--
You can control how Node is hosted within IIS using the following options:
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
* node_env: will be propagated to node as NODE_ENV environment variable
* debuggingEnabled - controls whether the built-in debugger is enabled
See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
-->
<!--<iisnode watchedFiles="web.config;*.js"/>-->
</system.webServer>
</configuration>
我们在azure上主持了该项目并且工作正常。我们的天蓝色网络应用资源也使用 iisnode 。但是在我们使用 iisnode 的帮助下在IIS上部署本地计算机时,我们会收到以下错误:
答案 0 :(得分:0)