Skip to content

Commit

Permalink
Auth framework started
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan McCartney committed Nov 15, 2023
1 parent f1f0f97 commit 99e9903
Show file tree
Hide file tree
Showing 8 changed files with 437 additions and 5 deletions.
16 changes: 13 additions & 3 deletions bin/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ const favicon = require("serve-favicon");
const helmet = require("helmet");
const httpLogger = require("@utils/http-logger");
const mustacheExpress = require("mustache-express");
const rateLimit = require("express-rate-limit");

// rate limiting
const apiLimiter = rateLimit({
windowMs: 5 * 60 * 1000,
max: process.env.RATE_LIMIT || 100,
});

// get environment
const nodeEnv = process.env.NODE_ENV || "production";
Expand All @@ -17,6 +24,7 @@ const pageRouter = require("@routes/page");
const systemRouter = require("@routes/system");
const playlistRouter = require("@routes/playlist");

const authRouter = require("@routes/auth");
const hlsRouter = require("@routes/hls");
const udpRouter = require("@routes/udp");
const rtpRouter = require("@routes/rtp");
Expand Down Expand Up @@ -61,10 +69,12 @@ app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());

app.use("/", apiLimiter);
app.use("/documentation", documentation);
app.use("/api/system", systemRouter);
app.use("/api/playlist", playlistRouter);
app.use("/api/hls", hlsRouter);
app.use("/api/auth", authRouter);

//Input Routes /api/INPUT_FORMAT/OUTPUT_FORMAT
app.use("/api/vmaf", vmafRouter);
Expand All @@ -77,7 +87,7 @@ app.use("/api/rtp", rtpRouter);
app.use("/api/bars", barsRouter);

// Redirect /api to /documentation
app.use("/api", function (req, res, next) {
app.use("/api", (req, res, next) => {
res.redirect("/documentation");
});

Expand All @@ -94,14 +104,14 @@ if (process.env.WEB_GUI) {
}

// catch 404 and forward to error handler
app.use(function (req, res, next) {
app.use((req, res, next) => {
const err = new Error("File Not Found");
err.status = 404;
next(err);
});

// error handler
app.use(function (error, req, res, next) {
app.use((error, req, res, next) => {
res.status(error.status || 500).json({
status: error.status,
message: error.message,
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ services:
PORT: 80
HOST: "localhost"
WEB_GUI: "true"
AUTH_KEY: "averysecretkey"
AUTH_USER: admin
AUTH_PASSWORD: admin
ports:
- 80:80
Loading

0 comments on commit 99e9903

Please sign in to comment.