来自 Sinatra Base 对象.获取应用程序的端口,包括基础对象

编程入门 行业动态 更新时间:2024-10-25 12:25:53
本文介绍了来自 Sinatra Base 对象.获取应用程序的端口,包括基础对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个 Sinatra::Base 对象,我想将它包含在我所有的网络应用程序中.在那个基类中,我有启动时调用的 configure 方法.

I have a Sinatra::Base object that I would like to include in all of my web apps. In that base class I have the configure method which is called on start-up.

我希望配置代码可以使用集中式数据库注册"该服务.注册时需要发送的信息是如何联系这个网络服务的信息……比如主机和端口.

I would like that configure code to 'register' that service with a centralized database. The information that needs to be sent when registering is the information on how to contact this web-service... things like host and port.

然后,我计划拥有一个监控服务,该服务将监控所有已注册的服务,并偶尔 ping 它们以确保它们仍然正常运行.

I then plan on having a monitoring service that will spin over all registered services and occasionally ping them to make sure they are still up and running.

在配置方法中,我无法获取端口信息.'self.settings.port' 变量在这种方法中似乎不起作用.

In the configure method I am having trouble getting the port information. The 'self.settings.port' variable doesn't seem to work in this method.

a) 关于如何获取端口的任何想法?我有主持人.

a) any ideas on how to get the port? I have the host.

b) 是否有一个 sinatra 插件已经做了这样的事情,所以我不必自己编写?:-)

b) is there a sinatra plug-in that already does something like this so I don't have to write it myself? :-)

//在我的 Sinatra::Base 代码中.让我们称之为 register_me.rb

//in my Sinatra::Base code. lets call it register_me.rb

注册我<辛纳特拉::基地

RegisterMe < Sinatra::Base

配置做

//保存主机和端口信息到数据库

//save host and port information to database

结束

获取'/check_status'

get '/check_status'

//返回状态

结束

//在我的网络服务代码中

//in my web service code

require register_me//此时sinatra会初始化RegisterMe对象并调用configure

require register_me //at this point, sinatra will initialize the RegisterMe object and call configure

发布 ('/blah')

post ('/blah')

//此特定网络服务的方法示例

//example of a method for this particular web service

结束

推荐答案

Sinatra::Application.port 将返回正确的端口

Sinatra::Application.port will return the correct port

这篇关于来自 Sinatra Base 对象.获取应用程序的端口,包括基础对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 06:14:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1130540.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   端口   应用程序   基础   Sinatra

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!