From d96973a50ba432e034afae26c4c3bd6faaf8fd45 Mon Sep 17 00:00:00 2001 From: akpi816218 Date: Fri, 3 May 2024 11:50:31 -0700 Subject: [PATCH] fixies --- package-lock.json | 33 ++++++++++++--------------------- package.json | 4 ++-- src/index.ts | 32 ++++++++++++++++++-------------- src/server.ts | 17 +++++------------ 4 files changed, 37 insertions(+), 49 deletions(-) diff --git a/package-lock.json b/package-lock.json index 65ccc59..ae8e8af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,10 +10,10 @@ "@deno/kv": "^0.7.0", "@discordjs/collection": "^2.0.0", "@napi-rs/canvas": "^0.1.52", - "cors": "^2.8.5", "discord.js": "^14.14.1", "dotenv": "^16.4.5", "express": "^4.19.2", + "helmet": "^7.1.0", "jsoning": "^1.0.1", "node-fetch": "^3.3.2", "node-schedule": "^2.1.1", @@ -3460,17 +3460,6 @@ "version": "1.0.6", "license": "MIT" }, - "node_modules/cors": { - "version": "2.8.5", - "license": "MIT", - "dependencies": { - "object-assign": "^4", - "vary": "^1" - }, - "engines": { - "node": ">= 0.10" - } - }, "node_modules/cosmiconfig": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-9.0.0.tgz", @@ -4886,6 +4875,14 @@ "node": ">= 0.4" } }, + "node_modules/helmet": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/helmet/-/helmet-7.1.0.tgz", + "integrity": "sha512-g+HZqgfbpXdCkme/Cd/mZkV0aV3BZZZSugecH03kl38m/Kmdx8jKjBikpDj2cr+Iynv4KpYEviojNdTJActJAg==", + "engines": { + "node": ">=16.0.0" + } + }, "node_modules/help-me": { "version": "5.0.0", "license": "MIT" @@ -6580,13 +6577,6 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, - "node_modules/object-assign": { - "version": "4.1.1", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/object-inspect": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", @@ -8046,9 +8036,10 @@ } }, "node_modules/tar": { - "version": "6.2.0", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.1.tgz", + "integrity": "sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==", "dev": true, - "license": "ISC", "dependencies": { "chownr": "^2.0.0", "fs-minipass": "^2.0.0", diff --git a/package.json b/package.json index e921dff..e80b6e0 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "@deno/kv": "^0.7.0", "@discordjs/collection": "^2.0.0", "@napi-rs/canvas": "^0.1.52", - "cors": "^2.8.5", "discord.js": "^14.14.1", "dotenv": "^16.4.5", "express": "^4.19.2", + "helmet": "^7.1.0", "jsoning": "^1.0.1", "node-fetch": "^3.3.2", "node-schedule": "^2.1.1", @@ -52,4 +52,4 @@ "up": "ncu -u && npm i", "prepare": "husky" } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 8a090ad..141fa43 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,7 +27,7 @@ import { dirname, join } from 'path'; import { fileURLToPath } from 'url'; import { logger } from './logger'; import { readdirSync } from 'fs'; -import { scheduleJob } from 'node-schedule'; +import { RecurrenceSpecObjLit, scheduleJob } from 'node-schedule'; import { openKv } from '@deno/kv'; import { Jsoning } from 'jsoning'; import { BirthdayData } from './struct/database'; @@ -81,10 +81,15 @@ const server = createServer( route: '/invite' }, { - handler: (_req, res) => res.sendStatus(client.isReady() ? 200 : 503), + handler: (_req, res) => res.redirect('/status'), method: Methods.GET, route: '/' }, + { + handler: (_req, res) => res.sendStatus(client.isReady() ? 200 : 503), + method: Methods.GET, + route: '/status' + }, { handler: (req, res) => { if ( @@ -94,10 +99,6 @@ const server = createServer( res.status(415).end(); else if (client.isReady()) res - .header({ - 'Access-Control-Allow-Origin': 'https://discog.opensourceforce.net', - Vary: 'Origin' - }) .status(200) .contentType('application/json') .send({ @@ -113,7 +114,7 @@ const server = createServer( else res.status(503).end(); }, method: Methods.GET, - route: '/api/bot' + route: '/bot' }, { handler: (req, res) => { @@ -124,10 +125,6 @@ const server = createServer( res.status(415).end(); else if (client.isReady()) res - .header({ - 'Access-Control-Allow-Origin': 'https://discog.opensourceforce.net', - Vary: 'Origin' - }) .status(200) .contentType('application/json') .send({ @@ -141,7 +138,7 @@ const server = createServer( else res.status(503).end(); }, method: Methods.GET, - route: '/api/commands' + route: '/commands' } ); logger.debug('Created server instance.'); @@ -307,8 +304,15 @@ process.on('SIGINT', () => { process.exit(0); }); -// Schedule the bdayInterval function to run every day at 12:00 AM PST for a server running 7 hours ahead of PST -scheduleJob('0 7 * * *', () => bdayInterval().catch(e => logger.error(e))); +// Schedule the bdayInterval function to run every day at 12:00 AM PST +scheduleJob( + { + tz: 'America/Los_Angeles', + hour: 0, + minute: 0 + } satisfies RecurrenceSpecObjLit, + () => bdayInterval().catch(e => logger.error(e)) +); logger.debug('Scheduled birthday interval.'); server.listen(process.env.PORT ?? PORT); diff --git a/src/server.ts b/src/server.ts index add9084..72433fe 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,15 +1,12 @@ import express, { Request, Response } from 'express'; -import cors from 'cors'; +import helmet from 'helmet'; export enum Methods { DELETE = 'delete', GET = 'get', - /** @public */ HEAD = 'head', PATCH = 'patch', - /** @public */ POST = 'post', - /** @public */ PUT = 'put' } @@ -26,14 +23,10 @@ export function createServer(...routes: Route[]) { } // cors app.use( - cors({ - origin: 'https://discog.opensourceforce.net/', - methods: [Methods.DELETE, Methods.GET, Methods.PATCH].map(e => - e.toUpperCase() - ), - maxAge: 86400, - allowedHeaders: ['Content-Type', 'Authorization'], - credentials: true + helmet({ + crossOriginResourcePolicy: { + policy: 'same-site' + } }) ); return app;