init
This commit is contained in:
45
testserver/index.js
Normal file
45
testserver/index.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const express = require('express');
|
||||
const expressStatus = require('express-status-monitor');
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(expressStatus());
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Hello world');
|
||||
});
|
||||
|
||||
app.get('/regex', (req, res) => {
|
||||
const userAgent = `aaaa${req.headers['user-agent']}`;
|
||||
res.send(`greedy regex (a+)+ ${(/(a+)+/).test(userAgent)}`);
|
||||
});
|
||||
|
||||
app.get('/crypto', (req, res) => {
|
||||
const buf = crypto.randomBytes(256);
|
||||
res.send(`crypto.randomBytes(256): ${buf}`);
|
||||
});
|
||||
|
||||
app.get('/file', (req, res) => {
|
||||
const hash = crypto.createHash('sha512');
|
||||
const filename = path.resolve(__dirname, 'package-lock.json');
|
||||
const stream = fs.ReadStream(filename);
|
||||
|
||||
const randomString = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
||||
hash.update(randomString);
|
||||
|
||||
stream.on('data', (data) => {
|
||||
hash.update(data);
|
||||
});
|
||||
|
||||
// making digest
|
||||
stream.on('end', () => {
|
||||
res.send(`file hash: ${hash.digest('hex')}`);
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(3000, () => {
|
||||
console.log('Test server on port 3000!');
|
||||
});
|
||||
Reference in New Issue
Block a user