0

I'm working with firebase functions and it is very hard to mange it index.js

index.js files like:

index.js

I want to be index.js and sub domain routing in apitest.js with express.js

index.js
apis -> test.js

index.js

const express = require('express');
const functions = require('firebase-functions');

const app = express();
...
const funcTestApi = require('./apis/apitest');

exports.apitest = functions.https.onRequest(app => {
    funcTestApi.router(app);
});

apitest.js

exports.router = function(app) {
    app.get('/foo', (req, res) => {
        res.status(200).json('hello');
    });

    app.get('/bar', (req, res) => {
        res.status(200).json('world');
    });

    ... // other url route 
}

Log:

http http://localhost:5000/project-name/us-central1/apitest/foo
http http://localhost:5000/project-name/us-central1/apitest/bar
...

info: Execution took 60000 ms, finished with status: 'timeout'

It's not working.

J.M
  • 1
  • 1
  • 1
    Take a look at the answers to this question: https://stackoverflow.com/questions/43486278/how-do-i-structure-cloud-functions-for-firebase-to-deploy-multiple-functions-fro – Scott Kronheim Nov 10 '17 at 12:40
  • 1
    Possible duplicate of [How do I structure Cloud Functions for Firebase to deploy multiple functions from multiple files?](https://stackoverflow.com/questions/43486278/how-do-i-structure-cloud-functions-for-firebase-to-deploy-multiple-functions-fro) – DoesData Nov 10 '17 at 14:42
  • Thank for your replay @ScottKronheim But, I want to know about sub domain router in apitest.js with express.js In [this question](https://stackoverflow.com/questions/43486278/how-do-i-structure-cloud-functions-for-firebase-to-deploy-multiple-functions-fro) there is no way about split http functions – J.M Nov 12 '17 at 23:36

1 Answers1

0

I found solution. Write return code, then it's work

apitest.js

exports.router = function(app) {
    app.get('/foo', (req, res) => {
        res.status(200).json('hello');
    });

    app.get('/bar', (req, res) => {
        res.status(200).json('world');
    });

    ... // other url route 

    return app; // <-- here
}
J.M
  • 1
  • 1