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`. ...@@ -46,6 +46,12 @@ Use `SITE_mycard.moe: php://fpm.example.com:9000/path/to/site`.
- `EXPIRES` Specify expires time. Default `10m`. - `EXPIRES` Specify expires time. Default `10m`.
- `PHP_EXTRA` Extra entry in `location`. - `PHP_EXTRA` Extra entry in `location`.
#### Redirect
Use `SITE_mycard.moe: redirect+https://example.com`.
- `CODE` Specify redirect code. Default `301`.
### Global ### Global
- `PURGE_ALLOWED` IPs allowed to do PURGE request. - `PURGE_ALLOWED` IPs allowed to do PURGE request.
......
...@@ -42,18 +42,28 @@ interface FileRenderData extends SiteRenderData { ...@@ -42,18 +42,28 @@ interface FileRenderData extends SiteRenderData {
expires: string; expires: string;
} }
export interface StaticRenderData extends FileRenderData { export interface StaticRenderData extends FileRenderData {
static: true; static: true;
browse?: boolean; browse?: boolean;
} }
export interface PhpRenderData extends FileRenderData { export interface PhpRenderData extends FileRenderData {
php: true; php: true;
upstream: string; upstream: string;
phpExtra?: 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 { export interface RenderData {
purgeAllowed?: string[]; purgeAllowed?: string[];
...@@ -107,7 +117,7 @@ async function getSiteData( ...@@ -107,7 +117,7 @@ async function getSiteData(
expires: parser.getString('EXPIRES') || '10m', expires: parser.getString('EXPIRES') || '10m',
browse: parser.getBoolean('BROWSE'), browse: parser.getBoolean('BROWSE'),
} as StaticRenderData; } as StaticRenderData;
} else if (targetUrl.protocol === 'php:') { } else if (targetUrl.protocol === 'php:') {
specificRenderData = { specificRenderData = {
php: true, php: true,
root: targetUrl.pathname, root: targetUrl.pathname,
...@@ -116,6 +126,12 @@ async function getSiteData( ...@@ -116,6 +126,12 @@ async function getSiteData(
upstream: targetUrl.host, upstream: targetUrl.host,
phpExtra: parser.getArray('PHP_EXTRA'), phpExtra: parser.getArray('PHP_EXTRA'),
} as PhpRenderData; } 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 { } else {
specificRenderData = { specificRenderData = {
proxy: true, proxy: true,
......
...@@ -257,6 +257,9 @@ http { ...@@ -257,6 +257,9 @@ http {
expires {{expires}}; expires {{expires}};
try_files $uri $uri/ /{{index}}?$query_string; try_files $uri $uri/ /{{index}}?$query_string;
{{/php}} {{/php}}
{{#redirect}}
return {{code}} {{upstream}};
{{/redirect}}
{{#locationExtra}} {{#locationExtra}}
{{.}} {{.}}
{{/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