无法使用Angular在NodeJS服务器中获取/ html

我开始一个页面Angular项目,但是当我尝试显示一个HTML时,我收到了“Can not GET / server”的回应。

这是我的app.js:

var express = require('express'); var path = require('path'); var favicon = require('serve-favicon'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var mongoose = require('mongoose'); // Mongoose: Libreria para conectar con MongoDB // Iniciando express var app = express(); app.all('/*', function(req, res, next) { // CORS headers res.header("Access-Control-Allow-Origin", "*"); // restrict it to the required domain res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); }); require('mongoose-middleware').initialize(mongoose); // Conexión a la base de datos de MongoDB que tenemos en local mongoose.connect('mongodb://localhost/cities2', function(err, res) { if (err) throw err; console.log('Conectado con éxito a la Base de Datos'); }); // Plantillas app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); //Middlewares express app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); //la ruta a los archivos estaticos (HTML, JS, ... app.use(express.static(path.join(__dirname + '/public'))); //servidor var router = express.Router(); var server = require('http').Server(app); app.use(router); // API Rutas routes = require('./routes/users')(app); routes = require('./routes/index')(app); /* app.get('*', function(req, res) { res.sendfile('./public/index.html'); });*/ app.get('/', function(req, res) { res.render('/public/index.html', {}); }); // Start server server.listen(8000, function() { console.log("Node server running on http://localhost:8000/server"); }); module.exports = app; 

然后,index.html:

 <!DOCTYPE html> <html ng-app="cities2"> <head> <link rel="stylesheet" href="/public/assets/css/bootstrap.min.css" /> <link rel="stylesheet" href="/public/assets/css/reset.css" /> </head> <body> <h1> Pagina Indice </h1> <!-- jQuery --> <script src="assets/js/jquery.js"></script> <script src="assets/js/jquery.min.js"></script> <script src="assets/js/bootstrap.min.js"></script> <script src="assets/js/respond.min.js"></script> <script src="assets/js/holder.js"></script> <script src="assets/js/angular.min.js"></script> <script src="assets/js/angular-route.min.js"></script> <script src="assets/js/angular-ui-router.min.js"></script> <!--Scripts --> <script src="assets/js/main.js"></script> <!-- Controllers --> <script src="assets/js/controllers/userCtrl.js"></script> </body> </html> 

最后,main.js:

 var cities2 = angular.module('cities2',[ 'ui.router', 'ngRoute' ]); cities2.config(function ($routeProvider, $stateProvider,$urlRouterProvider) { // Set up the states /*$routeProvider.when('/server', { templateUrl: '/assets/views/user.html', controller: 'userCtrl' })*/ $stateProvider .state('index', { url: "/", templateUrl: "/public/index.html" }) .state('server', { url: "/server", templateUrl: "/assets/views/user.html", controller: 'userCtrl' }) }); 

我知道index.html正在加载,但是当我把user.html url:localhost:8000 / server我收到消息,我写上面的“无法GET /服务器”

有人知道为什么吗?

       

网上收集的解决方案 "无法使用Angular在NodeJS服务器中获取/ html"