在Vue.js内的Firebase托管Node.js遇到问题吗?

时间:2019-06-09 09:14:24

标签: node.js firebase vue.js firebase-hosting

我有使用节点js完成的服务器和使用vuejs完成的客户端代码。最初,nodejs尚未完成,因此vuejs可以正常工作。但是,现在我分为两部分,客户端文件夹具有前端,其余部分是服务器端,这是在node.js中完成的。

我正在发布如何在vuejs中运行nodejs进行firebase部署。现在,控制台上显示的问题是

  

很抱歉,没有JavaScript,projectname无法正常工作   已启用。请启用它以继续。

我的项目结构:

  • 客户端[文件夹]
  • dist [文件夹]
  • 模型
  • node_modules
  • app.js
  • Dokerfiles
  • firebase.json
  • package.json
  • package-lock.json
  • publish-firebase-test.yaml
  • update-buildtools-.yaml

Firebase.json

 {
"hosting": {
"public": "dist",
"rewrites": [
  {
    "source": "**",
    "destination": "/index.html",
    "function": "app"
  }
],
"ignore": [
  "firebase.json",
  "**/.*",
  "**/node_modules/**"
],
"headers": [ {
  "source": "**/*.@(eot|otf|ttf|ttc|woff|font.css)",

  "headers": [ {
    "key": "Access-Control-Allow-Origin",
    "value": "*"
  } ]
}, {
  "source": "**/*.@(jpg|jpeg|gif|png)",
  "headers": [ {
    "key": "Cache-Control",
    "value": "max-age=7200"
  } ]
}, {
  "source": "404.html",
  "headers": [ {
    "key": "Cache-Control",
    "value": "max-age=300"
  } ]
 } ],

  "cleanUrls": true
  }
 }

客户端[文件夹]-> vue.config。

const path = require('path')

module.exports = {
devServer: {
compress: true,
disableHostCheck: true,
  },
 outputDir: path.resolve(__dirname, '../dist'), // build all the assets inside server/dist folder
 pluginOptions: {
 'style-resources-loader': {
  preProcessor: 'scss',
  patterns: [path.resolve(__dirname, './src/styles/global.scss')]
 }
 },
 chainWebpack: config => {
  if (config.plugins.has('optimize-css')) {
  config.plugins.delete('optimize-css')
  }
 }
}

客户端[文件夹]-> src->服务-> Api.js

 import axios from 'axios'

  export default() => {
  return axios.create({
  baseURL: `https://dev-xxxxxxx-com.firebaseapp.com`
  // https://dev-xxxxxxx-com.firebaseapp.com/
  // http://localhost:8081
  })
 }

app.js [node js code]

const express = require('express')
const bodyParser = require('body-parser')
 const cors = require('cors')
const morgan = require('morgan')
var firebase = require('firebase');
const functions = require('firebase-functions');

 const axios = require('axios');
 const credentials = new Buffer('testing:testing123').toString('base64')


 const app = express()
 app.use(morgan('combined'))
app.use(bodyParser.json())
app.use(cors())


var Post = require("./models/post");

  const firebaseConfig = {
  apiKey: "AIzaSyBDwqFKPt4D0eIspjsziweLI0nc49BRDrU",
  authDomain: "cloudthrifty-demo.firebaseapp.com",
 databaseURL: "https://cloudthrifty-demo.firebaseio.com",
 projectId: "cloudthrifty-demo",
 storageBucket: "cloudthrifty-demo.appspot.com",
 messagingSenderId: "638814042535",
appId: "1:638814042535:web:221da9fcf361554b"
};
firebase.initializeApp(firebaseConfig);
var db = firebase.firestore();


app.get('/GCPScheduler', (req, res) => {
res.send(
 [{
   title: "Hello World!",
  description: "Hi there! How are you?"
  }]
 )
})
 // serve dist folder
 if (process.env.NODE_ENV === 'production') {
 // Static folder
 app.use(express.static(__dirname + '/dist'));
 // Handle SPA
 app.get('*', (req, res) => res.sendFile(__dirname + '/dist/index.html'));

}

 // Add new post
app.post('/list-server', (req, res) => {
 var token = req.body.token;
 var ccExp = req.body.ccExp;
 var cardNumber = req.body.cardNumber;
 var currentUserUUID = req.body.currentUserUUID;
 var amount = req.body.amount;
 console.log(token);
console.log(ccExp);
console.log(cardNumber);
console.log(currentUserUUID);
console.log(amount);

(async() => {

const paymentRequest = await getAuthTokenForThePayment({
    account: cardNumber,
    merchid: '496160873888',
    amount: amount, // Smallest currency unit. e.g. 100 cents to charge $1.00
    expiry: ccExp,
    currency: 'USD'
});

const charge = await makeCharge({
    merchid: paymentRequest.data.merchid, 
    retref: paymentRequest.data.retref
});

console.log(charge);
console.log(charge.data.respstat)

if (charge.data.respstat == 'A'){

  var data = db.collection('transactionTable').doc(charge.data.retref);

  var setAlan = data.set({
    'respstat': charge.data.respstat,
    'retref': charge.data.retref,
    'account': charge.data.account,
    'token': charge.data.token,
    'batchid': charge.data.batchid,
    'amount': charge.data.amount,
    'resptext': charge.data.resptext,
    'respcode': charge.data.respcode,
    'commcard': charge.data.commcard,
    'setlstat': charge.data.setlstat,

  });

  res.send(charge.data.respstat);


} else if(charge.data.respstat == 'B'){

  console.log("Declined");
  res.send(charge.data.respstat);


}else if(charge.data.respstat == 'C'){
  console.log("Retry");
  res.send(charge.data.respstat);


}





})();

  const getAuthTokenForThePayment = async (data) => {

  try {

  const config = {
      headers: {
          'Content-Type': 'application/json',
          'Authorization': `Basic ${credentials}`
      }
  };

  const URL = 'https://fts.cardconnect.com:6443/cardconnect/rest/auth';

  return await axios.put(URL, data, config);

} catch (error) {

  throw (error);

  }
}

const makeCharge = async (data) => {

   try {

  const config = {
      headers: {
          'Content-Type': 'application/json',
          'Authorization': `Basic ${credentials}`
      }
  };

  const URL = 'https://fts.cardconnect.com:6443/cardconnect/rest/capture';

  return await axios.put(URL, data, config);

 } catch (error) {

  throw (error);

  }
}

 // app.listen(process.env.PORT || 8081)
exports.app = functions.https.onRequest(app);

任何帮助,不胜感激。

0 个答案:

没有答案