From a4048178126ce60c44c347f78c47d0ba881f55a6 Mon Sep 17 00:00:00 2001 From: Sebastien DUMETZ Date: Mon, 8 Jul 2024 11:16:26 +0200 Subject: [PATCH] add deprecation warning and redirects for deprecated routes --- source/server/routes/index.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/source/server/routes/index.ts b/source/server/routes/index.ts index cedb119b..f3bd3538 100644 --- a/source/server/routes/index.ts +++ b/source/server/routes/index.ts @@ -1,9 +1,10 @@ import path from "path"; import util from "util"; + import cookieSession from "cookie-session"; import express from "express"; -import bodyParser from "body-parser"; + import UserManager from "../auth/UserManager.js"; import { BadRequestError, HTTPError } from "../utils/errors.js"; @@ -207,7 +208,27 @@ export default async function createServer(config = defaultConfig) :Promise{ + // Signal deprecation using the non-standard Deprecation header + // https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-deprecation-header + res.set("Deprecation", "@"+Math.round(new Date("2024-07-08T00:00:00.000Z").getTime()/1000).toString()); + //Expected sunset date, approximately + res.set("Sunset", 'Wed, 01 Jan 2025 00:00:00 GMT'); + let pathname = req.originalUrl.replace("/api/v1/", "/"); + if(/^\/log(?:in|out)/.test(pathname)){ + pathname = "/auth"+pathname; + }else if(pathname.endsWith("history")){ + pathname = "/history"+pathname.replace("/scenes", "").replace("/history", ""); + }else if(pathname.endsWith("/permissions")){ + pathname = "/auth/access"+pathname.replace("/scenes", "").replace("/permissions", ""); + } + console.log('Path : %s => %s', req.originalUrl, pathname); + res.redirect(301, pathname); + }, `/api/v1 routes are deprecated. Use the new shorter naming scheme`)); const log_errors = process.env["TEST"] !== 'true'; const isTTY = process.stderr.isTTY;