Я использую Firebase, экспресс с машинописью, и я получаю сообщение об ошибке, используя Firebase serve - только хостинг, функции .
Мой код следующий:
* Внутри src У меня есть каталог с именем контроллеры и внутри data-controller.ts файл со следующим кодом:
export class DataController {
public router: Router
public cultura = "";
public coleccio = "";
public esProduccio:string = "";
constructor() {
this.router = Router();
this.init();
}
public static GetController(): Router {
var router: Router;
router.get('/:cultura/:coleccio/:esProduccio', (req, resp) => {
let cultura = req.params.cultura;
let coleccio = req.params.coleccio;
let esProduccio = req.params.esProduccio;
let dal = new DAL_Base(esProduccio);
dal.Get(cultura, coleccio).then(function (res) {
resp.send(JSON.stringify(res));
}).catch(function (error)
{
console.log(error);
resp.send(error)
});
});
return router;
}
init() {
this.router.get('/:cultura/:coleccio/:esProduccio', (req, resp) => {
let cultura = req.params.cultura;
let coleccio = req.params.coleccio;
let esProduccio = req.params.esProduccio;
let dal = new DAL_Base(esProduccio);
dal.Get(cultura, coleccio).then(function (res) {
resp.send(JSON.stringify(res));
}).catch(function (error)
{
console.log(error);
resp.send(error)
});
});
} }
Мой основной код, app.ts , это:
import { DataController } from "controllers/data-controller";
const functions = require("firebase-functions");
const express = require("express");
export class App {
constructor () {
}
funcion(): void {
var data: DataController = new DataController();
}
}
const app = new App();
exports.app = functions.https.onRequest(app);
My firebase.json :
{
"hosting": {
"public": "public",
"rewrites": [{
"source": "**",
"function": "app"
},{
"source": "**",
"function": "DataController"
}]
},
"functions": {
"predeploy": "npm --prefix functions run build"
}
}
My package.json is:
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "dist/app.js",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.16.4",
"firebase-admin": "~7.0.0",
"@types/debug": "0.0.31",
"@types/express": "^4.16.0",
"@types/express-serve-static-core": "^4.16.0",
"babel-polyfill": "^6.26.0",
"body-parser": "^1.18.3",
"cjs": "0.0.11",
"commonjs": "0.0.1",
"debug": "^4.1.0",
"grunt-cli": "^1.3.2",
"gulp-typescript": "^5.0.0-alpha.3",
"http": "0.0.0",
"jade": "^1.11.0",
"mongodb": "^3.1.10",
"mongoose": "^5.4.1",
"morgan": "^1.7.0",
"request": "^2.88.0",
"systemjs": "^2.1.1",
"ts-node": "^7.0.1",
"typings": "^2.1.1"
},
"devDependencies": {
"@types/body-parser": "0.0.33",
"@types/cors": "^2.8.4",
"@types/mongoose": "^5.3.6",
"@types/morgan": "^1.7.32",
"babel-preset-es2015": "^6.24.1",
"express-serve-static-core": "^0.1.1",
"firebase-functions": "^2.3.0",
"grunt": "^1.0.3",
"grunt-contrib-jshint": "^2.0.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-ts": "^6.0.0-beta.21",
"grunt-tslint": "^5.0.2",
"gulp-babel": "^8.0.0",
"linq-es2015": "^2.4.33",
"ts-lint": "^4.5.1",
"ts-loader": "^5.4.5",
"tslint": "^5.12.0",
"typescript": "^3.2.2",
"webpack-node-externals": "^1.7.2"
},
"private": true
}
tsconfig.json is:
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "узел",
"довольно": правда,
"sourceMap": правда,
"target": "es2015",
"lib": ["dom", "esnext"],
"outDir": "./dist",
"baseUrl": "./src",
"AlwaysStrict": правда
},
"include": ["src / ** / *. ts"],
"exclude": ["node_modules"]
}
Я получаю эту ошибку:
i functions: Preparing to emulate functions.
i hosting: Serving hosting files from: public
+ hosting: Local server: http://localhost:5000
Warning: You're using Node.js v10.13.0 but the Google Cloud Functions runtime is only available in Node.js 6 (Deprecated), Node.js 8, and Node.js 10 (Beta). Therefore, results from running emulated functions may not match production behavior.
! functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
! functions: Error from emulator. Error parsing triggers: Cannot find module 'controllers/data-controller'
Try running "npm install" in your functions directory before deploying.
Как я могу решить это?
когда я не заявляю, что DataController не работает. Я проверил, чтобы объявить это в constrooctor и ни один.
Thx