@@ -18,11 +18,14 @@ const bodyParser = require('body-parser')
18
18
app . use ( bodyParser . json ( { limit : '50mb' } ) ) ;
19
19
app . use ( bodyParser . urlencoded ( { extended : true } ) ) ;
20
20
21
- app . all ( `/` , ( req , res ) => {
22
- res . send ( 'Hello World!' ) ;
21
+ const api_root = process . env . API_ROOT ? process . env . API_ROOT . trim ( ) . replace ( / \/ + $ / , '' ) : '' ;
22
+ // console.log(api_root, process.env);
23
+
24
+ app . all ( `${ api_root } /` , ( req , res ) => {
25
+ res . send ( 'Hello World!' + `API ROOT = ${ api_root } ` ) ;
23
26
} ) ;
24
27
25
- app . post ( `/update` , ( req , res ) => {
28
+ app . post ( `${ api_root } /update` , ( req , res ) => {
26
29
const { encrypted, uuid } = req . body ;
27
30
// none of the fields can be empty
28
31
if ( ! encrypted || ! uuid ) {
@@ -40,7 +43,7 @@ app.post(`/update`, (req, res) => {
40
43
res . json ( { "action" :"error" } ) ;
41
44
} ) ;
42
45
43
- app . all ( `/get/:uuid` , ( req , res ) => {
46
+ app . all ( `${ api_root } /get/:uuid` , ( req , res ) => {
44
47
const { uuid } = req . params ;
45
48
// none of the fields can be empty
46
49
if ( ! uuid ) {
@@ -82,7 +85,7 @@ app.use(function (err, req, res, next) {
82
85
83
86
const port = 8088 ;
84
87
app . listen ( port , ( ) => {
85
- console . log ( `Server start on http://localhost:${ port } ` ) ;
88
+ console . log ( `Server start on http://localhost:${ port } ${ api_root } ` ) ;
86
89
} ) ;
87
90
88
91
function cookie_decrypt ( uuid , encrypted , password )
@@ -93,4 +96,4 @@ function cookie_decrypt( uuid, encrypted, password )
93
96
const parsed = JSON . parse ( decrypted ) ;
94
97
return parsed ;
95
98
}
96
-
99
+
0 commit comments