Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform express.router是否与GCP和xA1上的端点兼容;_Google Cloud Platform_Google Cloud Functions - Fatal编程技术网

Google cloud platform express.router是否与GCP和xA1上的端点兼容;

Google cloud platform express.router是否与GCP和xA1上的端点兼容;,google-cloud-platform,google-cloud-functions,Google Cloud Platform,Google Cloud Functions,我在nodeJs中开发了一些服务,我想移动到GCP,问题是我使用express.router实现了它,有没有办法移动/配置GCP端点以使用express.router路由我的呼叫,或者我需要摆脱该路由器并以更直接的方式路由?是可能的,您需要将express依赖项添加到包json并导出xrouter函数 我用它来测试快速路由 package.json { "name": "sample-http", "version": "0.0.1", "dependencies": {

我在nodeJs中开发了一些服务,我想移动到GCP,问题是我使用express.router实现了它,有没有办法移动/配置GCP端点以使用express.router路由我的呼叫,或者我需要摆脱该路由器并以更直接的方式路由?

是可能的,您需要将express依赖项添加到包json并导出xrouter函数

我用它来测试快速路由

package.json


{
  "name": "sample-http",
  "version": "0.0.1",
  "dependencies": {
    "express": "^4.16.4"
  }
}



index.js

const express = require('express');
const app = express();

var router = express.Router()

// a middleware function with no mount path. This code is executed for every request to the router
router.use(function (req, res, next) {
console.log('Time:', Date.now())
next()
})

// a middleware sub-stack shows request info for any type of HTTP request to the /user/:id path
router.use('/user/:id', function (req, res, next) {
console.log('Request URL:', req.originalUrl)
next()
}, function (req, res, next) {
console.log('Request Type:', req.method)
next()
})

// a middleware sub-stack that handles GET requests to the /user/:id path
router.get('/user/:id', function (req, res, next) {
// if the user ID is 0, skip to the next router
if (req.params.id === '0') next('route')
// otherwise pass control to the next middleware function in this stack
else next()
}, function (req, res, next) {
// render a regular page
res.send('regular')
})

// handler for the /user/:id path, which renders a special page
router.get('/user/:id', function (req, res, next) {
console.log(req.params.id)
res.send('special')
})

// mount the router on the app
app.use('/', router)

exports.xrouter = app;
您需要调用的函数是xrouter