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:
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/
|
/node_modules/
|
||||||
/.env
|
/.env
|
||||||
|
/.vercel
|
||||||
|
|
|
@ -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
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,
|
||||||
|
});
|
||||||
|
};
|
19
index.js
19
index.js
|
@ -1,11 +1,14 @@
|
||||||
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;
|
||||||
|
|
||||||
passport.use(
|
passport.use(
|
||||||
new BasicStrategy(function(username, password, done) {
|
new BasicStrategy(function (username, password, done) {
|
||||||
return done(
|
return done(
|
||||||
null,
|
null,
|
||||||
HTTP_USERNAME != null &&
|
HTTP_USERNAME != null &&
|
||||||
|
@ -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);
|
||||||
|
|
|
@ -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
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