Skip to content

Commit cef46ad

Browse files
authored
Update app.js
1 parent 792960e commit cef46ad

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

api/app.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ const bodyParser = require('body-parser')
1818
app.use(bodyParser.json({limit : '50mb' }));
1919
app.use(bodyParser.urlencoded({ extended: true }));
2020

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}`);
2326
});
2427

25-
app.post(`/update`, (req, res) => {
28+
app.post(`${api_root}/update`, (req, res) => {
2629
const { encrypted, uuid } = req.body;
2730
// none of the fields can be empty
2831
if (!encrypted || !uuid) {
@@ -40,7 +43,7 @@ app.post(`/update`, (req, res) => {
4043
res.json({"action":"error"});
4144
});
4245

43-
app.all(`/get/:uuid`, (req, res) => {
46+
app.all(`${api_root}/get/:uuid`, (req, res) => {
4447
const { uuid } = req.params;
4548
// none of the fields can be empty
4649
if (!uuid) {
@@ -82,7 +85,7 @@ app.use(function (err, req, res, next) {
8285

8386
const port = 8088;
8487
app.listen(port, () => {
85-
console.log(`Server start on http://localhost:${port}`);
88+
console.log(`Server start on http://localhost:${port}${api_root}`);
8689
});
8790

8891
function cookie_decrypt( uuid, encrypted, password )
@@ -93,4 +96,4 @@ function cookie_decrypt( uuid, encrypted, password )
9396
const parsed = JSON.parse(decrypted);
9497
return parsed;
9598
}
96-
99+

0 commit comments

Comments
 (0)