add auth
This commit is contained in:
parent
cfc2d0040b
commit
bc8e58e472
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
||||
node_modules
|
||||
node_modules
|
||||
data
|
||||
14
README.md
14
README.md
@ -4,6 +4,9 @@
|
||||
|
||||
## Create Docker image
|
||||
|
||||
npm i
|
||||
|
||||
docker build -t simple-http-upload:0.1.0 .
|
||||
|
||||
docker build -t 172.22.102.100:40016/team-mmkb/simple-http-upload:0.1.0 .
|
||||
|
||||
@ -20,10 +23,19 @@ docker push 172.22.102.100:40016/team-mmkb/simple-http-upload:0.1.0
|
||||
|
||||
# Run
|
||||
|
||||
docker run --rm -p 3000:3000 -v ./data:/data simple-http-upload:0.1.0
|
||||
|
||||
docker run --rm -p 3000:3000 -v ./data:/data 172.22.102.100:40016/team-mmkb/simple-http-upload:0.1.0
|
||||
|
||||
|
||||
docker run --rm -p 3000:3000 -v ./data:/data -e API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtbWtiIiwibmFtZSI6Im1ta2IiLCJpYXQiOjE1MTYyMzkwMjJ9.vBHcF6SFhImcGC4xDxKdPyq3shjNTPkVxkvdDyfx7Ss simple-http-upload:0.1.0
|
||||
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
curl -XPOST -F 'data=@test-5.txt' localhost:3000/
|
||||
```
|
||||
|
||||
curl -XPOST -F 'data=@test-1.txt' --header "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtbWtiIiwibmFtZSI6Im1ta2IiLCJpYXQiOjE1MTYyMzkwMjJ9.vBHcF6SFhImcGC4xDxKdPyq3shjNTPkVxkvdDyfx7Ss" localhost:3000/
|
||||
```
|
||||
|
||||
|
||||
8
index.js
8
index.js
@ -9,6 +9,14 @@ const config = process.env.config || '{ "uploadGroups": [{ "matcher": "^test.*\.
|
||||
|
||||
app.use(fileUpload())
|
||||
|
||||
app.use((req, res, next) =>{
|
||||
const authenticated = req.get('Authorization') === 'Bearer ' + process.env.API_KEY ;
|
||||
if(!authenticated){
|
||||
return res.status(401).send('Unauthorized');
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
const processGroups = () => {
|
||||
const files = [] = fs.readdirSync(uploadPath);
|
||||
|
||||
2
test-1.txt
Normal file
2
test-1.txt
Normal file
@ -0,0 +1,2 @@
|
||||
curl -XPOST -F 'data=@test-5.txt' localhost:3000/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user