【发布时间】:2018-03-16 21:50:45
【问题描述】:
我使用 angular cli 创建了一个 angular 4 项目。
现在我安装 express 并且我的 app.js 文件是
app.js
const express = require('express')
const app = express()
const bodyParser = require('body-parser');
const path = require('path');
const http = require('http');
const firebase = require("firebase");
app.use(express.static(path.join(__dirname, 'dist')));
var api = require('./server/routes/api');
app.use('/api', api);
app.get('*', (req, res) => {
res.render(path.join(__dirname, 'index.html'));
});
// Initialize Firebase
// TODO: Replace with your project's customized code snippet
//NOTE : I have replace the credentials
var config = {
apiKey: "<API_KEY>",
authDomain: "<PROJECT_ID>.firebaseapp.com",
databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
storageBucket: "<BUCKET>.appspot.com",
};
firebase.initializeApp(config);
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
现在如果我运行
npm app.js
我的 localhost:3000 正在工作,我的 angular js dist 文件夹显示在浏览器中。
如果我运行 localhost:3000/api 我会收到我的 api 调用。
现在,如何将其部署到 firebase。
我在一个单独的文件夹中尝试了 firebase.init,它正在创建一组 json 文件...
仍然不清楚,如何部署(我需要我的服务器文件夹,dist 文件夹)与 app.js 一起复制到 firebase 应用程序。
希望我很清楚。欢迎有正当理由的反对者。
【问题讨论】:
-
嗨,Alaksandar:你最终得到这个工作了吗?我也有同样的需求。
-
对不起。我放弃了,因为对我来说没有任何效果。