我几周来一直在努力进行这项部署,但没有成功。
为了让我的应用在本地运行,我运行domain.com/contact
和grunt serve
,但是,我尝试按照way it was deployed here作为示例。
我也尝试关注the instructions here,因为我的应用程序是由自耕农生成的。
- 如何运行node backend/app.js
代替node web.js
,您可以看到here该应用已与web.js文件相关联。
最后我运行grunt构建,然后将其部署到heroku,但是应用程序无法运行,它运行就好像它在本地运行而没有运行node backend/app.js
,显然这个文件没有得到运行或包括在内。例如,当我注册或登录时,没有任何反应。
node backend/app.js
app/app.js
'use strict';
var myApp = angular.module('myApp', ['ui.router', 'ngAnimate', 'satellizer']);
myApp.config(function($urlRouterProvider, $stateProvider, $httpProvider, $authProvider, API_URL){
$urlRouterProvider.otherwise('/');
$stateProvider
.state('main', {
url: '/',
templateUrl: '/views/main.html'
})
.state('register', {
url: '/register',
templateUrl: '/views/register.html',
controller: 'RegisterCtrl'
})
.state('login', {
url: '/login',
templateUrl: '/views/login.html',
controller: 'LoginCtrl'
})
.state('projectlist', {
url: '/projectlist',
templateUrl: '/views/projectlist.html',
controller: 'ProjectlistCtrl'
})
.state('logout', {
url: '/logout',
controller: 'LogoutCtrl'
});
$authProvider.loginUrl = API_URL + 'login'
$authProvider.signupUrl = API_URL + 'register'
$httpProvider.interceptors.push('authInterceptor')
})
.constant('API_URL', 'http://localhost:3000/')
backend/app.js
var express = require ('express');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var jwt = require('jwt-simple');
var passport = require('passport');
var LocalStrategy = require('./services/localStrategy.js');
var projectlist = require('./services/projectlist.js');
var createSendToken = require('./services/jwt.js');
var emailVerification = require('./services/emailVerification.js');
var app = express();
app.use(bodyParser.json());
app.use(passport.initialize());
passport.serializeUser(function (user, done) {
done(null, user.id);
});
app.use(function (req,res,next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
next();
});
passport.use('local-register', LocalStrategy.register);
passport.use('local-login', LocalStrategy.login);
app.post('/register', passport.authenticate('local-register'), function (req, res) {
emailVerification.send(req.user.email);
createSendToken(req.user, res);
});
app.get('/auth/verifyEmail', emailVerification.handler);
//using passport
app.post('/login', passport.authenticate('local-login'), function (req, res) {
createSendToken(req.user, res);
});
app.get('/projectlist', projectlist);
var server = app.listen(process.env.PORT || 3000, function () {
console.log('api listening on', server.address().port);
});
mongoose.connect('mongodb://username:password@ds123456.mlab.com:53845/myapp');
./web.js
var gzippo = require('gzippo');
var express = require('express');
var morgan = require('morgan');
var app = express();
app.use(morgan('dev'));
var apiFiles = './backend';
var wwwFiles = './app';
app.use(gzippo.staticGzip("" + __dirname + "/dist"));
app.use('/bower_components', express.static(__dirname + '/bower_components'));
app.use(express.static(__dirname));
app.get('/backend', function(req, res) {
res.sendfile('/api')
});
var server = app.listen(process.env.PORT || 3000, function () {
console.log('api listening on', server.address().port);
});
procfile
web: node web.js
package.json
{
"name": "potsdamapplication",
"private": true,
"devDependencies": {
"autoprefixer-core": "^5.2.1",
"grunt": "^0.4.5",
"grunt-angular-templates": "^0.5.7",
.... (all other grunt dependencies)
},
"engines": {
"node": ">=0.10.0"
},
"description": "This project is generated with [yo angular generator](https://github.com/yeoman/generator-angular) version 0.15.1.",
"version": "1.0.0",
"main": "Gruntfile.js",
"directories": {
"test": "test"
},
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.15.2",
.... (all other dependencies)
},
"scripts": {
"start": "nf start",
"test": "echo \"Error: no test specified\" && exit 1"
}
}
bower.json
最高赏金将在两天内给出最佳答案。 PROMISED
答案 0 :(得分:0)
也许这个提示有帮助:通过凉亭安装东西你需要添加一个buildpack:
heroku config:set BUILDPACK_URL='git://github.com/qnyp/heroku-buildpack-ruby-bower.git#run-bower'
我使用AngularJS演示应用程序为Ruby on Rails做了一次,在这里找到完整的故事:https://github.com/stiebitzhofer/rails-angular-bower-heroku