小编Gur*_*101的帖子

接下来没有定义,但我不明白如何在我的函数中定义它

当我尝试访问/ course/new时出现错误[ReferenceError: next is not defined].

我如何以及在哪里为我的断层函数定义下一个?如果我只是next像我在早期模型中所做的那样添加一个参数,我只会得到更多错误.

courseController:

module.exports = {

  'new':function(req, res, err){
    Student.findOne(req.param('takes'), function foundStudent (err, student){
      if (err) return next(err);
      if (!student) return next();
      res.view({
       student: student
      });
    });
  },

  create: function(req,res,next){
    Course.create(req.params.all(), function courseCreated (err, course){
      if(err) next(err);

      res.json(course)
    });
  }

};
Run Code Online (Sandbox Code Playgroud)

课程模式:

module.exports = {

  attributes: {
    code:{
      type: "string"
    },

    name:{
      type:"string"
    },

    takes:{
      model: 'student',
      required: true
    }
  }
};
Run Code Online (Sandbox Code Playgroud)

/course/new.ejs:

<form action="/course/create" method="post">
  <h2>Create a new course for …
Run Code Online (Sandbox Code Playgroud)

node.js sails.js

8
推荐指数
4
解决办法
1万
查看次数

有没有办法将 gitignore 模板添加到 azure devops 中的新项目中?

在 Azure Devops 中创建新存储库时,系统会提示您选择 .gitignore 模板文件。有没有办法将您自己的模板文件添加到此下拉列表中?

azure-devops

7
推荐指数
1
解决办法
7244
查看次数

尝试访问同一网络上的 grpc 服务器时 grpc 客户端 dns 解析失败

我正在尝试从 Python 客户端调用在 .Net Core 项目上运行的 GRPC 服务器。

当针对localhost:5001它运行时工作正常,但针对同一网络内机器的实际 IP 运行时,192.168.1.230:5001它不起作用,并且出现错误DNS resolution failed

我已经下载了 SSL 证书,目前正在从客户端将其作为文件读取。它在对抗时有效,localhost所以我认为这不是问题。

有没有更好的方法来进行这种让客户端在单独的设备上运行但与服务器在同一网络上的测试?在开发过程中将 GRPC 服务器托管在外部似乎并不是最好的解决方案。

Python代码:

import grpc
import datamessage_pb2 as datamessage
import datamessage_pb2_grpc as datamessageService


def main():
    print("Calling grpc server")
    with open("localhost.cer", "rb") as file:
        cert = file.read()
    credentials = grpc.ssl_channel_credentials(cert)
    channel = grpc.secure_channel("https://192.168.1.230:5001", credentials)
    # channel = grpc.secure_channel("localhost:5001", credentials)
    stub = datamessageService.StationDataHandlerStub(channel)
    request = datamessage.StationDataModel(
        temperature=22.3, humidity=13.3, soilMoisture=35.0)

    result = stub.RegisterNewStationData(request)
    print(result)


main()
Run Code Online (Sandbox Code Playgroud)

服务器设置在Program.cs: …

python .net-core grpc asp.net-core grpc-python

5
推荐指数
1
解决办法
1万
查看次数

Application Insights 将用户名添加到遥测

我试图在用户发出请求时在应用程序见解中记录用户的用户名。

我一直在尝试这样做:

 public class AppInsightsInitializer : ClientIpHeaderTelemetryInitializer
    {
        private readonly IHttpContextAccessor _httpContextAccessor;

        public AppInsightsInitializer(IHttpContextAccessor httpContextAccessor) : base(httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }

        protected override void OnInitializeTelemetry(HttpContext platformContext, RequestTelemetry requestTelemetry, ITelemetry telemetry)
        {
            var userName = _httpContextAccessor.HttpContext?.User?.Identity?.Name; // Only set when request failed...
            var ip = _httpContextAccessor.HttpContext?.Connection?.RemoteIpAddress?.ToString();
            if (userName != null) requestTelemetry.Context.User.AuthenticatedUserId= userName;
        }
    }
Run Code Online (Sandbox Code Playgroud)

在中注入并注册遥测后Startup.cs

 services.AddApplicationInsightsTelemetry(instrumentKey);
 services.AddSingleton<ITelemetryInitializer, AppInsights.AppInsightsInitializer>();
Run Code Online (Sandbox Code Playgroud)

但这会导致System.ObjectDisposedException: 'Safe handle has been closed

System.ObjectDisposedException
  HResult=0x80131622
  Message=Safe handle has been closed
  Source=mscorlib
  StackTrace:
   at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
   at …
Run Code Online (Sandbox Code Playgroud)

c# asp.net azure-application-insights

5
推荐指数
1
解决办法
2325
查看次数

Navigation.createNavigateOnClickListener 来自 onBindViewHolder?

我想在 中设置一个 onclicklisteneronBindViewHolder以便导航到不同的片段并将一些数据发送到该片段。

对于我的生活,我似乎无法找到让它发挥作用的方法。非常感谢任何和所有帮助!

适配器类:

class ListAdapter(private val list: List<Workout>): RecyclerView.Adapter<WorkoutViewHolder>() {

    override fun getItemCount(): Int{
        return list.size
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WorkoutViewHolder {
        val layoutInflater = LayoutInflater.from(parent.context)
        return WorkoutViewHolder(layoutInflater, parent)
    }

    override fun onBindViewHolder(holder: WorkoutViewHolder, position: Int) {
        val workout: Workout = list[position]
        holder.itemView.setOnClickListener{
            Toast.makeText(holder.itemView.context, "TEST", Toast.LENGTH_LONG).show()
            val id = workout.workoutId
            val bundle = Bundle()
            bundle.putInt("workoutId", id)
            Navigation.createNavigateOnClickListener(R.id.workoutDetailsFragment)
        }
        holder.bind(workout)
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以让吐司弹出,所以 onclicklistener 似乎正在工作。但是,导航部分不起作用。如果我只是在托管 recyclerview 的片段内设置一个按钮并添加button.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.workoutDetailsFragment))它可以很好地导航。所以问题似乎是从 onbindviewholder 内的 onclicklistener 内部调用导航功能

android kotlin android-recyclerview android-architecture-navigation

2
推荐指数
1
解决办法
1066
查看次数