|
|
|
|
|
const express = require('express'); |
|
|
|
const app = express(); |
|
|
|
let strValues = ''; |
|
|
|
const port = 7860; |
|
|
|
const password = process.env.PASSWORD || '123456' ; |
|
|
|
|
|
app.post('/SET', (req, res) => { |
|
|
|
let method = req.method; |
|
|
|
let pwd = req.query.pwd; |
|
|
|
if (!pwd || pwd !== password) { |
|
res.status(401).send('Invalid password'); |
|
return; |
|
} |
|
|
|
let setValue = req.header('Cookie-Values'); |
|
|
|
if (setValue) { |
|
strValues = setValue; |
|
|
|
res.send('Set value successfully'); |
|
} else { |
|
|
|
res.status(400).send('No Cookie-Values in header'); |
|
} |
|
}); |
|
|
|
|
|
app.all('/GET', (req, res) => { |
|
|
|
let method = req.method; |
|
|
|
let pwd = req.query.pwd; |
|
|
|
if (!pwd || pwd !== password) { |
|
res.status(401).send('Invalid password'); |
|
return; |
|
} |
|
|
|
let result = { result: { cookies: strValues } }; |
|
|
|
res.json(result); |
|
}); |
|
|
|
|
|
app.all('/CLS', (req, res) => { |
|
|
|
let method = req.method; |
|
|
|
let pwd = req.query.pwd; |
|
|
|
if (!pwd || pwd !== password) { |
|
res.status(401).send('Invalid password'); |
|
return; |
|
} |
|
|
|
strValues = ''; |
|
|
|
res.send('Clear value successfully'); |
|
}); |
|
|
|
|
|
app.all('/', (req, res) => { |
|
|
|
res.send('Please visit /SET /GET or /CLS with ?pwd=xxxxxx'); |
|
}); |
|
|
|
|
|
|
|
app.listen(port, () => { |
|
console.log(`Server is running on port ${port}`); |
|
}); |