Skip to content

Commit c90e4e3

Browse files
authoredSep 1, 2021
Redirects for dev mode short links (#465)
Adds a https://lit.dev/msg/<code> redirect for all warnings logged by Lit's dev mode. Half of lit/lit#2078. Other half is at lit/lit#2119.
1 parent 8f249b9 commit c90e4e3

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed
 

‎packages/lit-dev-server/src/index.ts

+12-17
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,23 @@ if (mode === 'playground') {
4343
}
4444

4545
app.use(async (ctx, next) => {
46-
if (ctx.path.match(/\/[^\/\.]+$/)) {
46+
// If there would be multiple redirects, resolve them all here so that we
47+
// serve just one HTTP redirect instead of a chain.
48+
let path = ctx.path;
49+
if (path.match(/\/[^\/\.]+$/)) {
4750
// Canonicalize paths to have a trailing slash, except for files with
4851
// extensions.
49-
ctx.status = 301;
50-
ctx.redirect(
51-
ctx.path + '/' + (ctx.querystring ? '?' + ctx.querystring : '')
52-
);
53-
} else if (ctx.path.endsWith('//')) {
52+
path += '/';
53+
}
54+
if (path.endsWith('//')) {
5455
// Koa static doesn't care if there are any number of trailing slashes.
5556
// Normalize this too.
57+
path = path.replace(/\/+$/, '/');
58+
}
59+
path = pageRedirects.get(path) ?? path;
60+
if (path !== ctx.path) {
5661
ctx.status = 301;
57-
ctx.redirect(
58-
ctx.path.replace(/\/+$/, '/') +
59-
(ctx.querystring ? '?' + ctx.querystring : '')
60-
);
61-
} else if (pageRedirects.has(ctx.path)) {
62-
// Handle any 1:1 page redirects
63-
ctx.status = 301;
64-
ctx.redirect(
65-
pageRedirects.get(ctx.path) +
66-
(ctx.querystring ? '?' + ctx.querystring : '')
67-
);
62+
ctx.redirect(path + (ctx.querystring ? '?' + ctx.querystring : ''));
6863
} else {
6964
await next();
7065
}

‎packages/lit-dev-server/src/redirects.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,26 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

7-
export const pageRedirects = new Map(
8-
[
9-
['/slack-invite/', 'https://join.slack.com/t/lit-and-friends/shared_invite/zt-llwznvsy-LZwT13R66gOgnrg12PUGqw'],
10-
]
11-
)
7+
// prettier-ignore
8+
export const pageRedirects = new Map([
9+
['/slack-invite', 'https://join.slack.com/t/lit-and-friends/shared_invite/zt-llwznvsy-LZwT13R66gOgnrg12PUGqw'],
10+
11+
['/msg/dev-mode', '/docs/tools/development/#development-and-production-builds'],
12+
// TODO(sorvell) https://github.com/lit/lit.dev/issues/455
13+
['/msg/multiple-versions', '/docs/tools/requirements/'],
14+
['/msg/polyfill-support-missing', '/docs/tools/requirements/#polyfills'],
15+
// TODO(sorvell) https://github.com/lit/lit.dev/issues/462
16+
['/msg/class-field-shadowing', '/docs/components/properties/#declare'],
17+
// TODO(aomarks) Should we add something specifically about this issue?
18+
['/msg/change-in-update', '/docs/components/properties/#when-properties-change'],
19+
['/msg/deprecated-import-path', '/docs/releases/upgrade/#update-packages-and-import-paths'],
20+
['/msg/removed-api', '/docs/releases/upgrade/#litelement'],
21+
['/msg/renamed-api', '/docs/releases/upgrade/#update-to-renamed-apis'],
22+
['/msg/undefined-attribute-value', '/docs/releases/upgrade/#litelement'],
23+
['/msg/request-update-promise', '/docs/releases/upgrade/#litelement'],
24+
].map(([path, redir]) => [
25+
// Trailing slashes are required because this redirect map is consulted after
26+
// standard lit.dev path canonicalization.
27+
path.match(/\/[^\/\.]+$/) ? path + '/' : path,
28+
redir,
29+
]));

0 commit comments

Comments
 (0)
Please sign in to comment.