Commit 55621bc9 authored by nanahira's avatar nanahira

add redirect+

parent 7b6d37f8
Pipeline #22333 passed with stages
in 55 minutes and 58 seconds
......@@ -46,6 +46,12 @@ Use `SITE_mycard.moe: php://fpm.example.com:9000/path/to/site`.
- `EXPIRES` Specify expires time. Default `10m`.
- `PHP_EXTRA` Extra entry in `location`.
#### Redirect
Use `SITE_mycard.moe: redirect+https://example.com`.
- `CODE` Specify redirect code. Default `301`.
### Global
- `PURGE_ALLOWED` IPs allowed to do PURGE request.
......
......@@ -42,18 +42,28 @@ interface FileRenderData extends SiteRenderData {
expires: string;
}
export interface StaticRenderData extends FileRenderData {
export interface StaticRenderData extends FileRenderData {
static: true;
browse?: boolean;
}
export interface PhpRenderData extends FileRenderData {
export interface PhpRenderData extends FileRenderData {
php: true;
upstream: string;
upstream: string;
phpExtra?: string[];
}
export type SpecificRenderData = PhpRenderData | StaticRenderData | ProxyRenderData;
export interface RedirectRenderData extends SiteRenderData {
redirect: true;
upstream: string;
code: number;
}
export type SpecificRenderData =
| PhpRenderData
| StaticRenderData
| ProxyRenderData
| RedirectRenderData;
export interface RenderData {
purgeAllowed?: string[];
......@@ -107,7 +117,7 @@ async function getSiteData(
expires: parser.getString('EXPIRES') || '10m',
browse: parser.getBoolean('BROWSE'),
} as StaticRenderData;
} else if (targetUrl.protocol === 'php:') {
} else if (targetUrl.protocol === 'php:') {
specificRenderData = {
php: true,
root: targetUrl.pathname,
......@@ -116,6 +126,12 @@ async function getSiteData(
upstream: targetUrl.host,
phpExtra: parser.getArray('PHP_EXTRA'),
} as PhpRenderData;
} else if (targetUrl.protocol.startsWith('redirect+')) {
specificRenderData = {
redirect: true,
upstream: targetUrl.href.slice(10),
code: parser.getNumber('REDIRECT_CODE') || 301,
} as RedirectRenderData;
} else {
specificRenderData = {
proxy: true,
......
......@@ -257,6 +257,9 @@ http {
expires {{expires}};
try_files $uri $uri/ /{{index}}?$query_string;
{{/php}}
{{#redirect}}
return {{code}} {{upstream}};
{{/redirect}}
{{#locationExtra}}
{{.}}
{{/locationExtra}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment