diff --git a/api/.eslintrc.js b/api/.eslintrc.js index 88075e2..53392fa 100644 --- a/api/.eslintrc.js +++ b/api/.eslintrc.js @@ -2,6 +2,7 @@ module.exports = { extends: ['standard-with-typescript'], rules: { '@typescript-eslint/indent': ['error', 4], - '@typescript-eslint/semi': ['error', 'always'] + '@typescript-eslint/semi': ['error', 'always'], + '@typescript-eslint/strict-boolean-expressions': 'off' } }; diff --git a/api/src/database.ts b/api/src/database.ts index 3f64d6c..c209295 100644 --- a/api/src/database.ts +++ b/api/src/database.ts @@ -10,6 +10,6 @@ const sequelize = new Sequelize({ }); sequelize.addModels([Container, Page]); -sequelize.sync(); +void sequelize.sync(); export default sequelize; diff --git a/api/src/index.ts b/api/src/index.ts index 45acba6..372d36a 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -16,6 +16,7 @@ import v1Router from './v1'; import './database'; import { getSitemap } from './utils/sitemap'; +import { wrapAsync } from './utils/express'; import { Page } from './models'; const app = express(); @@ -24,11 +25,11 @@ const app = express(); app.use(cors({ credentials: true, origin: [ - new RegExp('gruppe-adler.de$', 'i'), - new RegExp('localhost:[0-9]+$', 'i'), - new RegExp('127.0.0.1:[0-9]+$', 'i'), - new RegExp('127.0.0.1$', 'i'), - new RegExp('localhost$', 'i') + /gruppe-adler.de$/i, + /localhost:[0-9]+$/i, + /127.0.0.1:[0-9]+$/i, + /127.0.0.1$/i, + /localhost$/i ] })); @@ -48,7 +49,7 @@ app.use('/api/v1', v1Router); app.use('/uploads', express.static(join(__dirname, '../data/uploads'))); -app.get('/sitemap.xml', async (req, res) => { +app.get('/sitemap.xml', wrapAsync(async (req, res) => { res.header('Content-Type', 'application/xml'); res.header('Content-Encoding', 'gzip'); @@ -59,7 +60,7 @@ app.get('/sitemap.xml', async (req, res) => { console.error(err); res.status(500).end(); } -}); +})); // frontend if (existsSync(join(__dirname, '../frontend'))) { @@ -86,7 +87,7 @@ if (existsSync(join(__dirname, '../frontend'))) { express.static(join(__dirname, '../frontend'), { setHeaders: (res: Response, path: string) => { if (/.+\.(?!html).*$/i.test(path)) { - const cacheControl = cacheHeaders[path] || 'public, max-age=2678400'; + const cacheControl = cacheHeaders[path] ?? 'public, max-age=2678400'; res.header('Cache-Control', cacheControl); } else { @@ -97,7 +98,7 @@ if (existsSync(join(__dirname, '../frontend'))) { ); let pages: string[] = []; - const cachePages = async () => { + const cachePages = async (): Promise => { const newPages = await Page.findAll({ attributes: ['slug'] }) as Array>; const slugs = newPages.map(p => p.slug); @@ -108,7 +109,7 @@ if (existsSync(join(__dirname, '../frontend'))) { Page.addHook('afterCreate', cachePages); Page.addHook('afterDestroy', cachePages); - cachePages(); + void cachePages(); app.get('*', (req: Request, res: Response, next: NextFunction) => { if (!req.accepts('application/html')) { next(); diff --git a/api/src/utils/EventsService.ts b/api/src/utils/EventsService.ts index f246c30..9651373 100644 --- a/api/src/utils/EventsService.ts +++ b/api/src/utils/EventsService.ts @@ -21,7 +21,7 @@ export class ArmaEventsService { // this constructor is actually important to make sure it is private (singleton pattern) // eslint-disable-next-line no-useless-constructor, @typescript-eslint/no-empty-function private constructor () { - this.cacheEvents(); + void this.cacheEvents(); // fetch new events every half an hour setInterval(this.cacheEvents.bind(this), 1000 * 60 * 30); diff --git a/api/src/utils/express.ts b/api/src/utils/express.ts index 72b2c1a..fe51b2f 100644 --- a/api/src/utils/express.ts +++ b/api/src/utils/express.ts @@ -2,7 +2,9 @@ import { type Request, type Response, type NextFunction, type RequestHandler } f import { validationResult } from 'express-validator'; import ResponseError from './ResponseError'; -export const wrapAsync = (fn: RequestHandler): RequestHandler => (req: Request, res: Response, next: NextFunction): void => { +type AsyncRequestHandler = (...params: Parameters) => Promise>; + +export const wrapAsync = (fn: AsyncRequestHandler): RequestHandler => (req: Request, res: Response, next: NextFunction): void => { // Make sure to `.catch()` any errors and pass them along to the `next()` // middleware in the chain, in this case the error handler. fn(req, res, next).catch(next); diff --git a/api/src/utils/sso.ts b/api/src/utils/sso.ts index 8d4d279..fc8fd14 100644 --- a/api/src/utils/sso.ts +++ b/api/src/utils/sso.ts @@ -42,7 +42,7 @@ async function fetchUser (token: string): Promise { return json.data.authenticate; } -async function validateToken (token: string) { +async function validateToken (token: string): Promise { const user = await fetchUser(token); if (user === null) throw new ReponseError(401);