Skip to content

Commit d5a45a5

Browse files
committed
Fix multipart form POST in Node Server Example
1 parent 55a6613 commit d5a45a5

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

node-server-example/server.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,29 @@ app.use(session({
1818
}));
1919

2020
app.use('/favicon.ico', express.static('public/images/favicon.ico'));
21+
22+
2123
// parse application/json
2224
app.use(bodyParser.json());
2325
// parse application/x-www-form-urlencoded
2426
app.use(bodyParser.urlencoded({ extended: true }));
2527
// for parsing multipart/form-data
2628
const multer = require('multer')()
29+
30+
app.post('/example_endpoint', multer.any(), function (req, res) {
31+
//the token comes in from the fron end in the request body
32+
const myVoiceIt = new VoiceIt2WebSDK.Voiceit2(config.VOICEIT_API_KEY, config.VOICEIT_API_TOKEN, {sessionExpirationTimeHours:config.SESSION_EXPIRATION_TIME_HOURS});
33+
myVoiceIt.makeCall(req, res, function(jsonObj){
34+
if (
35+
(jsonObj.callType.includes('Liveness') && jsonObj.jsonResponse.success) || // Liveness Server returns success true/false instead of responseCode
36+
(!jsonObj.callType.includes('Liveness') && jsonObj.jsonResponse.responseCode === 'SUCC')
37+
) {
38+
// Activate Session with userId
39+
req.session.userId = jsonObj.userId;
40+
}
41+
});
42+
});
43+
2744
app.use(multer.array());
2845
// serve all static files in public directory
2946
app.use(express.static('public'));
@@ -76,19 +93,6 @@ app.get('/console', function (req, res) {
7693
}
7794
})
7895

79-
app.post('/example_endpoint', multer.any(), function (req, res) {
80-
//the token comes in from the fron end in the request body
81-
const myVoiceIt = new VoiceIt2WebSDK.Voiceit2(config.VOICEIT_API_KEY, config.VOICEIT_API_TOKEN, {sessionExpirationTimeHours:config.SESSION_EXPIRATION_TIME_HOURS});
82-
myVoiceIt.makeCall(req, res, function(jsonObj){
83-
if (
84-
(jsonObj.callType.includes('Liveness') && jsonObj.jsonResponse.success) || // Liveness Server returns success true/false instead of responseCode
85-
(!jsonObj.callType.includes('Liveness') && jsonObj.jsonResponse.responseCode === 'SUCC')
86-
) {
87-
// Activate Session with userId
88-
req.session.userId = jsonObj.userId;
89-
}
90-
});
91-
});
9296

9397
app.get('/content_language', function (req, res) {
9498
res.json({contentLanguage: config.CONTENT_LANGUAGE});

0 commit comments

Comments
 (0)