简体   繁体   English

在系统中提供最近活动的最佳方法是什么

[英]What is the best approach for providing the recent activity in a system

I need to save the recent activity of a user in my system.我需要在我的系统中保存用户最近的活动。 Any idea how I can implement this?知道如何实现吗? Links to any articles?链接到任何文章? Im using ExpressJS running on node as the server.我使用在节点上运行的 ExpressJS 作为服务器。

Thanks in advance.提前致谢。

It depends which actions should be saved as user activity.这取决于应将哪些操作保存为用户活动。
To handle GET / POST requests:处理 GET / POST 请求:

  1. Create MySQL database named «activity» with the table «requests» in MySQL Workbench like this:在 MySQL Workbench 中使用表 «requests» 创建名为 «activity» 的 MySQL 数据库,如下所示:

数据库

  1. Install an official MySQL connector by typing通过键入安装官方 MySQL 连接器

     npm install @mysql/xdevapi --save --save-exact
  2. Open your index.js and put something like this:打开你的 index.js 并输入如下内容:

     const express = require('express'); const mysqlx = require('@mysql/xdevapi'); const app = express(); function log(url) { mysqlx.getSession('dbLogin:dbPassword@localhost:33060').then(session => { session.getSchema('activity').getTable('requests').insert([ 'username', 'url' ]).values([ 'User', url ]).execute(); }); } app.get('/', (req, res) => { log(req.url); res.sendFile(__dirname + '/index.html'); }); app.get('/info', (req, res) => { log(req.url); res.sendFile(__dirname + '/info.html'); }); app.listen(3000);

For more detailed information like mouse / keyboard events, you can send POST request with AJAX ( see this answer for details ) or use WebSockets有关鼠标/键盘事件等更多详细信息,您可以使用 AJAX 发送 POST 请求(有关详细信息,请参阅此答案)或使用WebSockets

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM