ANgular不使用express,但单独工作很好

时间:2016-10-24 10:11:56

标签: html css angularjs express

我在这里失去它:我的角度代码单独工作,但当我使用它表达它不起作用。我服务于静态文件,因为我在服务器上得到404消息。这是我的角度代码:

var app = angular.module('tiks', []);

app.controller('mainController', function($scope){

     $scope.posts = [];
     $scope.newPost = {created_by: '', text: '', create_at: ''};

      $scope.post = function(){
        $scope.newPost.created_at = Date.now();
        $scope.posts.push($scope.newPost);
        $scope.newPost = {created_by: '', text: '', created_at: ''};
  };
});

这是我的服务器代码:

// dependencies
var express = require('express');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var expressSession = require('express-session');
var mongoose = require('mongoose');
var hash = require('bcrypt-nodejs');
var path = require('path');
var passport = require('passport');
var localStrategy = require('passport-local' ).Strategy;



// mongoose
mongoose.connect('mongodb://localhost/mean-auth');

// user schema/model
var User = require('./models/user.js');

// create instance of express
var app = express();
//les chemins
app.use("/#", express.static(__dirname + '../client/partials/javascripts'));
app.use( express.static(__dirname + '/../client/partials/stylesheets'));
app.use('/?#/', express.static(__dirname + '../client/partials/stylesheets'));
app.use('/?', express.static(__dirname + '../client/partials/stylesheets'));
app.use('/#', express.static(__dirname + '../client/partials/stylesheets'));
app.use('/style', express.static(__dirname + '../client/partials/stylesheets'));
app.use('http://localhost:3000/?#/', express.static(__dirname + '../client/partials/stylesheets'));






///les chemin
// require routes
var routes = require('./routes/api.js');

// define middleware
app.use(express.static(path.join(__dirname, '../client')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(require('express-session')({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());


app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, '../client/partials')));
// configure passport
passport.use(new localStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());

// routes
app.use('/user/', routes);

app.get('/', function(req, res) {
  res.sendFile(path.join(__dirname, '../client', 'index.html'));
});
app.get('/?#/', function(req, res) {
  res.sendFile(path.join(__dirname, '../client/views', 'index.html'));
});
// error hndlers
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

app.use(function(err, req, res) {
  res.status(err.status || 500);
  res.end(JSON.stringify({
    message: err.message,
    error: {}
  }));
});

module.exports = app;

和我服务器的另一部分:

var debug = require('debug')('passport-mongo');
var app = require('./app');


app.set('port', process.env.PORT || 3000);


var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});

感谢您的帮助,欢迎任何消化

0 个答案:

没有答案