Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import pg from 'pg';

const { Client } = pg;
import express from "express";
import bodyParser from "body-parser";
import isBot from "isbot";
import { isbot } from "isbot";
import querystring from "querystring";
import dotenv from "dotenv";
import bolt from "@slack/bolt";
Expand Down Expand Up @@ -69,8 +68,8 @@ let client;
const app = express();

app.use(forceHttps);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

const port = process.env.PORT || 3000;
app.listen(port, () => {
Expand Down Expand Up @@ -578,7 +577,7 @@ app.get("/odr!:odrid", (req, res) => {
res.redirect(302, "https://fulfillment.hackclub.com/odr!" + req.params.odrid);
})

app.get("/*", (req, res) => {
app.get("/*path", (req, res) => {
let slug = decodeURIComponent(req.path.substring(1));
const query = req.query;

Expand Down Expand Up @@ -687,7 +686,7 @@ async function logAccess(ip, ua, slug, url) {
if (process.env.LOGGING === "off") return;

const botUA = ["apex/ping/v1.0"];
if (process.env.BOT_LOGGING === "off" && (isBot(ua) || botUA.includes(ua))) return;
if (process.env.BOT_LOGGING === "off" && (isbot(ua) || botUA.includes(ua))) return;

let linkData;
try {
Expand All @@ -712,7 +711,7 @@ async function logAccess(ip, ua, slug, url) {
slug: slug,
url: url,
user_agent: ua,
bot: isBot(ua) || botUA.includes(ua),
bot: isbot(ua) || botUA.includes(ua),
counter: 1
};

Expand Down Expand Up @@ -1134,7 +1133,7 @@ function getClientIp(req) {
const forwardedIps = forwardedIpsStr.split(",");
return forwardedIps[0];
}
return req.connection.remoteAddress;
return req.socket.remoteAddress;
}

function forceHttps(req, res, next) {
Expand Down
Loading
Loading