Angularjs 在本地服务器的IIS上部署平均堆栈项目

Angularjs 在本地服务器的IIS上部署平均堆栈项目,angularjs,node.js,iis,mean-stack,iisnode,Angularjs,Node.js,Iis,Mean Stack,Iisnode,我试图在本地机器上使用iisnode在IIS上部署MEAN framework应用程序 我的api调用在IIS上托管后正常工作,但web应用程序页面未加载,因为它无法加载与web应用程序相关的必需css和js文件 Myserver.js包含以下代码:- var express = require('express'); var app = express(); var http = require('http').Server(app); var path = require('path');

我试图在本地机器上使用iisnode在IIS上部署MEAN framework应用程序

我的api调用在IIS上托管后正常工作,但web应用程序页面未加载,因为它无法加载与web应用程序相关的必需css和js文件

Myserver.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上主持了该项目,它运行良好。此外,我们的azure web app资源正在使用iisnode。但在本地计算机上,当我们借助iisnode在IIS上部署时,我们会得到以下错误:


.

您得到的错误告诉您您的配置无效

确保正确配置IIS。见以下示例:


这里有很多很好的资源和配置示例。

但我并不是说你错了。在国际海事组织,这更接近于一个评论而不是一个解决方案。一般来说,像“看例子,试着跟着做”、“阅读文档”和“我不知道你的问题是什么,所以按照教程去做”这样的话都不是答案。