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.
......
...@@ -53,7 +53,17 @@ export interface PhpRenderData extends FileRenderData { ...@@ -53,7 +53,17 @@ export interface PhpRenderData extends FileRenderData {
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[];
...@@ -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