【问题标题】:How to quick refresh a Google Cloud's Node.js app without having to go through "gcloud app deploy"?如何快速刷新 Google Cloud 的 Node.js 应用程序而无需通过“gcloud app deploy”?
【发布时间】:2019-05-24 14:03:39
【问题描述】:

有时我只需要对我的代码进行一些小的更改,例如更改变量的值(在 Google Cloud 上托管的 Nodejs app.js 上)。有没有办法在不通过“gcloud app deploy”部署整个应用程序的情况下更新文件?

【问题讨论】:

    标签: node.js google-cloud-platform


    【解决方案1】:

    不可以,应用程序的代码只能通过重新部署来更新。

    但是,如果您只是更改变量值,而不是硬编码它们,您可以使用 GET 参数并从 url 传递值。这样,您无需更改任何代码即可更改值,因此无需重新部署。

    来自修改official Nodejs sample的示例:

    'use strict';
    
    const express = require('express');
    const app = express();
    
    app.get('/', (req, res) => {
    
      var my_param = req.query.param;
      res
        .status(200)
        .send('The url gave me this: ' + my_param)
        .end();
    });
    
    // Start the server
    const PORT = process.env.PORT || 8080;
    app.listen(PORT, () => {
      console.log(`App listening on port ${PORT}`);
      console.log('Press Ctrl+C to quit.');
    });
    

    那么你在url中添加param值,例如:

    https://your-project.appspot.com/?param=123

    这将导致:

    网址给了我这个:123

    【讨论】:

    • 谢谢!这将在某些情况下节省部署。
    猜你喜欢
    • 2023-04-01
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    • 2021-04-27
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 2017-04-16
    相关资源
    最近更新 更多