简体   繁体   中英

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.

Thanks in advance.

It depends which actions should be saved as user activity.
To handle GET / POST requests:

  1. Create MySQL database named «activity» with the table «requests» in MySQL Workbench like this:

数据库

  1. Install an official MySQL connector by typing

     npm install @mysql/xdevapi --save --save-exact
  2. Open your index.js and put something like this:

     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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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