1
0
Fork 0
mirror of https://github.com/kou029w/http-echo.git synced 2025-01-18 16:08:13 +00:00

create vercel project files

This commit is contained in:
Nebel 2020-05-16 20:08:33 +09:00
parent af36d77317
commit 0b9083509b
6 changed files with 29 additions and 14 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/node_modules/ /node_modules/
/.env /.env
/.vercel

View file

@ -1,5 +1,7 @@
FROM node:alpine FROM node:alpine
WORKDIR /app
ADD package.json . ADD package.json .
RUN npm i RUN npm i
ADD api api
ADD index.js . ADD index.js .
CMD ["npm","start"] CMD ["npm","start"]

11
api/app.js Normal file
View 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,
});
};

View file

@ -1,5 +1,8 @@
const express = require("express"); const express = require("express");
const cookieParser = require("cookie-parser");
const morgan = require("morgan");
const passport = require("passport"); const passport = require("passport");
const { BasicStrategy } = require("passport-http"); const { BasicStrategy } = require("passport-http");
const { timingSafeEqual } = require("crypto"); const { timingSafeEqual } = require("crypto");
const { HTTP_USERNAME, HTTP_PASSWORD } = process.env; const { HTTP_USERNAME, HTTP_PASSWORD } = process.env;
@ -19,21 +22,13 @@ passport.use(
const app = express(); const app = express();
app.use(cookieParser());
app.use(morgan("combined"));
app.use(express.json()); app.use(express.json());
app.use(express.urlencoded({ extended: false })); app.use(express.urlencoded({ extended: false }));
app.use(express.raw({ type: "*/*" })); app.use(express.raw({ type: "*/*" }));
app.set("json spaces", 2); app.set("json spaces", 2);
app.all("/basic-auth", passport.authenticate("basic", { session: false })); app.all("/basic-auth", passport.authenticate("basic", { session: false }));
app.all("/*", function(req, res) { app.all("/*", require("./api/app.js"));
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.listen(process.env.PORT || 8080); app.listen(process.env.PORT || 8080);

View file

@ -8,9 +8,11 @@
"start": "node -r dotenv/config index.js" "start": "node -r dotenv/config index.js"
}, },
"dependencies": { "dependencies": {
"cookie-parser": "latest",
"express": "latest", "express": "latest",
"passport-http": "latest", "morgan": "latest",
"passport": "latest" "passport": "latest",
"passport-http": "latest"
}, },
"devDependencies": { "devDependencies": {
"dotenv": "latest", "dotenv": "latest",

4
vercel.json Normal file
View file

@ -0,0 +1,4 @@
{
"version": 2,
"routes": [{ "src": "/.*", "dest": "/api/app.js" }]
}