1
+ const express = require ( 'express' ) ;
2
+ const proxy = require ( './proxy' ) ;
3
+ const short = require ( 'short-uuid' ) ;
4
+ const path = require ( 'path' ) ;
5
+ const app = express ( ) ;
6
+ const { json } = require ( 'body-parser' ) ;
7
+
8
+ console . log ( 'Serving static asserts from .' )
9
+ app . use ( express . static ( path . join ( __dirname , '.' ) ) ) ;
10
+ app . use ( json ( { type : 'application/vnd.mcash.api.merchant.v1+json' } ) ) ;
11
+
12
+ proxy ( app ) ;
13
+
14
+ const history = [ ] ;
15
+
16
+ app . get ( '/callback' , function ( req , res ) {
17
+ const id = short . generate ( ) ;
18
+ console . log ( '-------------------------' )
19
+ console . log ( id ) ;
20
+ console . log ( 'Serving request for history' )
21
+
22
+ res . json ( { "callback_history" : history . slice ( 0 , 10 ) } ) ;
23
+ } ) ;
24
+
25
+ app . post ( '/callback' , function ( req , res ) {
26
+ const id = short . generate ( ) ;
27
+ console . log ( '-------------------------' )
28
+ console . log ( id ) ;
29
+ console . log ( req . method , req . url )
30
+ console . log ( req . headers )
31
+ console . log ( req . body ) ;
32
+
33
+ history . unshift ( { id, body : req . body } )
34
+
35
+ res . sendStatus ( 200 ) ;
36
+ } ) ;
37
+
38
+ app . get ( '/*' , function ( req , res ) {
39
+ res . sendFile ( path . join ( __dirname , '.' , 'index.html' ) ) ;
40
+ } ) ;
41
+
42
+ const port = 3000
43
+ console . log ( `Listening to 0.0.0.0:${ port } ` )
44
+ app . listen ( port ) ;
0 commit comments