mirror of
https://github.com/kou029w/http-echo.git
synced 2025-01-18 08:05:06 +00:00
create vercel project files
This commit is contained in:
parent
af36d77317
commit
0b9083509b
6 changed files with 29 additions and 14 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/node_modules/
|
||||
/.env
|
||||
/.vercel
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
FROM node:alpine
|
||||
WORKDIR /app
|
||||
ADD package.json .
|
||||
RUN npm i
|
||||
ADD api api
|
||||
ADD index.js .
|
||||
CMD ["npm","start"]
|
||||
|
|
11
api/app.js
Normal file
11
api/app.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
module.exports = (req, res) => {
|
||||
res.json({
|
||||
headers: req.headers,
|
||||
body: req.body == null ? null : req.body,
|
||||
host: req.headers.host,
|
||||
method: req.method,
|
||||
target: req.url,
|
||||
query: req.query,
|
||||
cookies: req.cookies,
|
||||
});
|
||||
};
|
17
index.js
17
index.js
|
@ -1,5 +1,8 @@
|
|||
const express = require("express");
|
||||
const cookieParser = require("cookie-parser");
|
||||
const morgan = require("morgan");
|
||||
const passport = require("passport");
|
||||
|
||||
const { BasicStrategy } = require("passport-http");
|
||||
const { timingSafeEqual } = require("crypto");
|
||||
const { HTTP_USERNAME, HTTP_PASSWORD } = process.env;
|
||||
|
@ -19,21 +22,13 @@ passport.use(
|
|||
|
||||
const app = express();
|
||||
|
||||
app.use(cookieParser());
|
||||
app.use(morgan("combined"));
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
app.use(express.raw({ type: "*/*" }));
|
||||
app.set("json spaces", 2);
|
||||
app.all("/basic-auth", passport.authenticate("basic", { session: false }));
|
||||
app.all("/*", function(req, res) {
|
||||
res.json({
|
||||
headers: req.headers,
|
||||
body: req.body.length > 0 ? req.body.toString() : null,
|
||||
form: req.is("urlencoded") ? req.body : null,
|
||||
json: req.is("json") ? req.body : null,
|
||||
method: req.method,
|
||||
target: req.url,
|
||||
host: req.headers.host
|
||||
});
|
||||
});
|
||||
app.all("/*", require("./api/app.js"));
|
||||
|
||||
app.listen(process.env.PORT || 8080);
|
||||
|
|
|
@ -8,9 +8,11 @@
|
|||
"start": "node -r dotenv/config index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"cookie-parser": "latest",
|
||||
"express": "latest",
|
||||
"passport-http": "latest",
|
||||
"passport": "latest"
|
||||
"morgan": "latest",
|
||||
"passport": "latest",
|
||||
"passport-http": "latest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"dotenv": "latest",
|
||||
|
|
4
vercel.json
Normal file
4
vercel.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"version": 2,
|
||||
"routes": [{ "src": "/.*", "dest": "/api/app.js" }]
|
||||
}
|
Loading…
Add table
Reference in a new issue