To make requests to Go API endpoints for registration from a PHP page, there needs to be local routing between the two servers. This method avoids needing Apache installed seperately for development builds while allowing it to still be used in production if necessary.master
@@ -1,45 +1,236 @@ | |||||
absolute_urls: false | absolute_urls: false | ||||
timezone: null | |||||
param_sep: ':' | |||||
wrapped_site: false | |||||
reverse_proxy_setup: false | |||||
force_ssl: false | |||||
force_lowercase_urls: true | |||||
custom_base_url: null | |||||
username_regex: '^[a-z0-9_-]{3,16}$' | |||||
pwd_regex: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}' | |||||
intl_enabled: true | |||||
http_x_forwarded: | |||||
protocol: true | |||||
host: false | |||||
port: true | |||||
ip: true | |||||
languages: | |||||
supported: null | |||||
default_lang: null | |||||
include_default_lang: true | |||||
include_default_lang_file_extension: true | |||||
translations: true | |||||
translations_fallback: true | |||||
session_store_active: false | |||||
http_accept_language: false | |||||
override_locale: false | |||||
pages_fallback_only: false | |||||
debug: false | |||||
home: | home: | ||||
alias: '/home' | |||||
alias: /home | |||||
hide_in_urls: false | |||||
pages: | pages: | ||||
type: regular | |||||
dirs: | |||||
- 'page://' | |||||
theme: quark | theme: quark | ||||
markdown: | |||||
extra: false | |||||
order: | |||||
by: default | |||||
dir: asc | |||||
list: | |||||
count: 20 | |||||
dateformat: | |||||
default: null | |||||
short: 'jS M Y' | |||||
long: 'F jS \a\t g:ia' | |||||
publish_dates: true | |||||
process: | process: | ||||
markdown: true | markdown: true | ||||
twig: false | twig: false | ||||
twig_first: false | |||||
never_cache_twig: false | |||||
events: | |||||
page: true | |||||
twig: true | |||||
markdown: | |||||
extra: false | |||||
auto_line_breaks: false | |||||
auto_url_links: false | |||||
escape_markup: false | |||||
special_chars: | |||||
'>': gt | |||||
'<': lt | |||||
valid_link_attributes: | |||||
- rel | |||||
- target | |||||
- id | |||||
- class | |||||
- classes | |||||
types: | |||||
- html | |||||
- htm | |||||
- xml | |||||
- txt | |||||
- json | |||||
- rss | |||||
- atom | |||||
append_url_extension: null | |||||
expires: 604800 | |||||
cache_control: null | |||||
last_modified: false | |||||
etag: true | |||||
vary_accept_encoding: false | |||||
redirect_default_code: '302' | |||||
redirect_trailing_slash: 1 | |||||
redirect_default_route: 0 | |||||
ignore_files: | |||||
- .DS_Store | |||||
ignore_folders: | |||||
- .git | |||||
- .idea | |||||
ignore_hidden: true | |||||
hide_empty_folders: false | |||||
url_taxonomy_filters: true | |||||
frontmatter: | |||||
process_twig: false | |||||
ignore_fields: | |||||
- form | |||||
- forms | |||||
cache: | cache: | ||||
enabled: true | enabled: true | ||||
check: | check: | ||||
method: file | method: file | ||||
driver: auto | driver: auto | ||||
prefix: 'g' | |||||
prefix: g | |||||
purge_at: '0 4 * * *' | |||||
clear_at: '0 3 * * *' | |||||
clear_job_type: standard | |||||
clear_images_by_default: false | |||||
cli_compatibility: false | |||||
lifetime: 604800 | |||||
gzip: false | |||||
allow_webserver_gzip: false | |||||
redis: | |||||
socket: '0' | |||||
password: null | |||||
database: null | |||||
server: null | |||||
port: null | |||||
memcache: | |||||
server: null | |||||
port: null | |||||
memcached: | |||||
server: null | |||||
port: null | |||||
twig: | twig: | ||||
cache: true | cache: true | ||||
debug: true | debug: true | ||||
auto_reload: true | auto_reload: true | ||||
autoescape: true | autoescape: true | ||||
undefined_functions: true | |||||
undefined_filters: true | |||||
safe_functions: { } | |||||
safe_filters: { } | |||||
umask_fix: false | |||||
assets: | assets: | ||||
css_pipeline: false | css_pipeline: false | ||||
css_pipeline_include_externals: true | |||||
css_pipeline_before_excludes: true | |||||
css_minify: true | css_minify: true | ||||
css_minify_windows: false | |||||
css_rewrite: true | css_rewrite: true | ||||
js_pipeline: false | js_pipeline: false | ||||
js_pipeline_include_externals: true | |||||
js_pipeline_before_excludes: true | |||||
js_module_pipeline: false | js_module_pipeline: false | ||||
js_module_pipeline_include_externals: true | |||||
js_module_pipeline_before_excludes: true | |||||
js_minify: true | js_minify: true | ||||
enable_asset_timestamp: false | |||||
enable_asset_sri: false | |||||
collections: | |||||
jquery: 'system://assets/jquery/jquery-3.x.min.js' | |||||
errors: | errors: | ||||
display: true | |||||
display: 1 | |||||
log: true | log: true | ||||
log: | |||||
handler: file | |||||
syslog: | |||||
facility: local6 | |||||
tag: grav | |||||
debugger: | debugger: | ||||
enabled: false | enabled: false | ||||
twig: true | |||||
provider: clockwork | |||||
censored: false | |||||
shutdown: | shutdown: | ||||
close_connection: true | close_connection: true | ||||
twig: true | |||||
images: | |||||
default_image_quality: 85 | |||||
cache_all: false | |||||
cache_perms: '0755' | |||||
debug: false | |||||
auto_fix_orientation: true | |||||
seofriendly: false | |||||
cls: | |||||
auto_sizes: false | |||||
aspect_ratio: false | |||||
retina_scale: '1' | |||||
defaults: | |||||
loading: auto | |||||
watermark: | |||||
image: 'system://images/watermark.png' | |||||
position_y: center | |||||
position_x: center | |||||
scale: 33 | |||||
watermark_all: false | |||||
media: | |||||
enable_media_timestamp: false | |||||
unsupported_inline_types: null | |||||
allowed_fallback_types: null | |||||
auto_metadata_exif: false | |||||
upload_limit: 2097152 | |||||
session: | |||||
enabled: true | |||||
initialize: true | |||||
timeout: 1800 | |||||
name: grav-site | |||||
uniqueness: path | |||||
secure: false | |||||
secure_https: true | |||||
httponly: true | |||||
samesite: Lax | |||||
split: true | |||||
domain: null | |||||
path: null | |||||
gpm: | gpm: | ||||
releases: stable | |||||
official_gpm_only: true | |||||
verify_peer: true | |||||
http: | |||||
method: auto | |||||
enable_proxy: true | |||||
proxy_url: null | |||||
proxy_cert_path: null | |||||
concurrent_connections: 5 | |||||
verify_peer: true | verify_peer: true | ||||
verify_host: true | |||||
accounts: | |||||
type: regular | |||||
storage: file | |||||
avatar: gravatar | |||||
flex: | |||||
cache: | |||||
index: | |||||
enabled: true | |||||
lifetime: 60 | |||||
object: | |||||
enabled: true | |||||
lifetime: 600 | |||||
render: | |||||
enabled: true | |||||
lifetime: 600 | |||||
strict_mode: | |||||
yaml_compat: false | |||||
twig_compat: false | |||||
blueprint_compat: false |
@@ -1,4 +1,4 @@ | |||||
last_checked: 1705024218 | |||||
last_checked: 1705428562 | |||||
data: | data: | ||||
- | - | ||||
title: 'macOS 14.0 Sonoma Apache Setup: Upgrading Homebrew' | title: 'macOS 14.0 Sonoma Apache Setup: Upgrading Homebrew' | ||||
@@ -1,4 +1,4 @@ | |||||
last_checked: 1705023122 | |||||
last_checked: 1705428561 | |||||
data: | data: | ||||
feed: | feed: | ||||
- | - | ||||
@@ -11,6 +11,16 @@ import Account from "./account.vue" | |||||
function create(user) { | function create(user) { | ||||
console.log(user) | console.log(user) | ||||
fetch(`/api/user`, | |||||
{method: 'POST', | |||||
body: JSON.stringify(user), | |||||
headers: { | |||||
"Accept": "application/json", | |||||
}, | |||||
}).then(resp => { | |||||
console.log(resp) | |||||
if (resp.ok) { return resp.json() } else { return resp.text() } | |||||
}).then(u => console.log(u)) | |||||
} | } | ||||
</script> | </script> | ||||
@@ -4,6 +4,8 @@ import ( | |||||
"os" | "os" | ||||
"os/exec" | "os/exec" | ||||
"net/http" | "net/http" | ||||
"net/http/httputil" | |||||
"net/url" | |||||
"net/mail" | "net/mail" | ||||
"log" | "log" | ||||
"sync" | "sync" | ||||
@@ -215,7 +217,8 @@ type Endpoint func (http.ResponseWriter, *sql.DB, *http.Request) | |||||
var ( | var ( | ||||
regexen = make(map[string]*regexp.Regexp) | regexen = make(map[string]*regexp.Regexp) | ||||
relock sync.Mutex | relock sync.Mutex | ||||
address = "127.0.0.1:8001" | |||||
address = "localhost:8001" | |||||
mainAddress = "localhost:8002" | |||||
) | ) | ||||
var paths = map[string]string { | var paths = map[string]string { | ||||
@@ -2537,8 +2540,7 @@ func api(w http.ResponseWriter, r *http.Request) { | |||||
r.Method == http.MethodGet && guard(r, 1): | r.Method == http.MethodGet && guard(r, 1): | ||||
getUser(w, db, r) | getUser(w, db, r) | ||||
case match(p, "/api/user", &args) && | case match(p, "/api/user", &args) && | ||||
r.Method == http.MethodPost && | |||||
guard(r, 1): | |||||
r.Method == http.MethodPost: | |||||
createUser(w, db, r) | createUser(w, db, r) | ||||
case match(p, "/api/user", &args) && | case match(p, "/api/user", &args) && | ||||
r.Method == http.MethodPatch && | r.Method == http.MethodPatch && | ||||
@@ -2639,7 +2641,7 @@ func route(w http.ResponseWriter, r *http.Request) { | |||||
page = pages[ "terms" ] | page = pages[ "terms" ] | ||||
case match(p, "/app", &args): | case match(p, "/app", &args): | ||||
page = pages[ "app" ] | page = pages[ "app" ] | ||||
default: | |||||
default: | |||||
http.NotFound(w, r) | http.NotFound(w, r) | ||||
return | return | ||||
} | } | ||||
@@ -2648,11 +2650,16 @@ func route(w http.ResponseWriter, r *http.Request) { | |||||
} | } | ||||
func serve() { | func serve() { | ||||
files := http.FileServer(http.Dir("")) | files := http.FileServer(http.Dir("")) | ||||
proxy, err := url.Parse("http://localhost:8002") | |||||
if err != nil { log.Fatal("invalid origin server URL") } | |||||
http.Handle("/assets/", files) | http.Handle("/assets/", files) | ||||
http.HandleFunc("/api/", api) | http.HandleFunc("/api/", api) | ||||
http.HandleFunc("/", route) | |||||
http.HandleFunc("/app", route) | |||||
http.Handle("/", httputil.NewSingleHostReverseProxy(proxy)) | |||||
log.Fatal(http.ListenAndServe(address, nil)) | log.Fatal(http.ListenAndServe(address, nil)) | ||||
} | } | ||||