【问题标题】:Change root of Mean application更改平均应用程序的根
【发布时间】:2015-04-22 11:22:12
【问题描述】:

我正在开发平均应用程序,我需要从另一个 url(例如(“/myApp”)而不是 root 加载我的 html、css,那么如何获得这个?我的意思是我想启动我的应用程序表单 url“localhost:3003/myApp”,默认情况下它在“localhost:3003/”上运行

我的配置文件是

 var express = require('express'),
        routes = require('./routes'),
        fs = require('fs'),
        bodyParser = require('body-parser'),
        router = express.Router();
        var port = 80;
        var app = module.exports = express(); 

        // Configuration
         //app.use(router);

        app.use(bodyParser());
        //app.use(express.methodOverride());
       app.use(express.static(__dirname + '/dev'));
        //app.use(express.compress());


    app.all('*', function (req, res, next) {
        res.header("Access-Control-Allow-Origin", "*");
        res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, Content-Length,X-Requested-With");
        res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
        next();
    })

    router.get('/', routes.index);

    router.get('/template/:name', routes.partials);

    // JSON API
    router.get('/api/name', routes.name);

    // redirect all others to the index (HTML5 history)
    router.get('*', routes.index);

    app.use('/', router);


       app.listen(3003, function(){
                console.log("Express server listening on port mode");
            });

    process.on('uncaughtException', function (err) {
        console.log((new Date).toUTCString() + ' uncaughtException:', err.message)
        console.log(err); //process.setMaxListeners(0);
       // process.setMaxListeners(0);
        process.exit(1)
    })

【问题讨论】:

标签: angularjs node.js express mean-stack


【解决方案1】:

更改:app.use('/', router);app.use('/myApp', router);

【讨论】:

  • 你的意思是,我还必须像 .state('home', { url: "/explorer", templateUrl: "views/main/partials/home.html" })
  • 对不起,但这不起作用,所有的 java 脚本文件正在加载,但 html 不来
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-20
  • 1970-01-01
  • 2014-03-03
  • 2018-07-19
  • 2021-05-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多