-
Notifications
You must be signed in to change notification settings - Fork 1
/
poc.js
59 lines (46 loc) · 1.82 KB
/
poc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Copyright 2021 BRAUN Nathanael
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/
const express = require('express');
const app = express()
const port = 3000
//app.set('query parser', function ( str ) {
// return qs.parse(str, { allowPrototypes: false });
//});
//app.set("query parser", "simple");
app.use(express.urlencoded({ extended: true }));
//app.use(bodyParser.urlencoded({ }))
app.get('/', ( req, res, next ) => {
const categories = req.query.categories;
console.log('[server] Received query : ', req.query);
console.log('[server] (categories instanceof Array) : ', (categories instanceof Array));
if ( !categories || !(categories instanceof Array) )
return next(new Error("'categories' must be an Array"))
console.log('[server] Do : req.query.categories.indexOf("123")');
console.time('[server] req.query.categories.indexOf("123")');
req.query.categories.indexOf("123")
console.timeEnd('[server] req.query.categories.indexOf("123")');
res.send('Hello World!');
process.exit(0)
})
app.post('/', ( req, res, next ) => {
//console.log(':::41: ', req);
const categories = req.body.categories;
console.log('[server] Received body : ', req.body, req.body.hasOwnProperty);
console.log('[server] (categories instanceof Array) : ', (categories instanceof Array));
if ( !categories || !(categories instanceof Array) )
return next(new Error("'categories' must be an Array"))
console.log('[server] Do : categories.indexOf("123")');
console.time('[server] categories.indexOf("123")');
categories.indexOf("123")
console.timeEnd('[server] categories.indexOf("123")');
res.send('Hello World!');
process.exit(0)
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})