Browse Source

Access main Grav site through Go reverse proxy

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
Immanuel Onyeka 1 year ago
parent
commit
3152ff716d
6 changed files with 2082 additions and 20 deletions
  1. +1854
    -0
      assets/admin-preset.css
  2. +204
    -13
      grav-admin/user/config/system.yaml
  3. +1
    -1
      grav-admin/user/data/feed/21232f297a57a5a743894a0e4a801fc3.yaml
  4. +1
    -1
      grav-admin/user/data/notifications/21232f297a57a5a743894a0e4a801fc3.yaml
  5. +10
    -0
      grav-admin/user/js/registration/registration.vue
  6. +12
    -5
      skouter.go

+ 1854
- 0
assets/admin-preset.css
File diff suppressed because it is too large
View File


+ 204
- 13
grav-admin/user/config/system.yaml View File

@@ -1,45 +1,236 @@
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:
alias: '/home'

alias: /home
hide_in_urls: false
pages:
type: regular
dirs:
- 'page://'
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:
markdown: true
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:
enabled: true
check:
method: file
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:
cache: true
debug: true
auto_reload: true
autoescape: true

undefined_functions: true
undefined_filters: true
safe_functions: { }
safe_filters: { }
umask_fix: false
assets:
css_pipeline: false
css_pipeline_include_externals: true
css_pipeline_before_excludes: true
css_minify: true
css_minify_windows: false
css_rewrite: true
js_pipeline: false
js_pipeline_include_externals: true
js_pipeline_before_excludes: true
js_module_pipeline: false
js_module_pipeline_include_externals: true
js_module_pipeline_before_excludes: true
js_minify: true

enable_asset_timestamp: false
enable_asset_sri: false
collections:
jquery: 'system://assets/jquery/jquery-3.x.min.js'
errors:
display: true
display: 1
log: true

log:
handler: file
syslog:
facility: local6
tag: grav
debugger:
enabled: false
twig: true
provider: clockwork
censored: false
shutdown:
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:
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_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
- 1
grav-admin/user/data/feed/21232f297a57a5a743894a0e4a801fc3.yaml View File

@@ -1,4 +1,4 @@
last_checked: 1705024218
last_checked: 1705428562
data:
-
title: 'macOS 14.0 Sonoma Apache Setup: Upgrading Homebrew'


+ 1
- 1
grav-admin/user/data/notifications/21232f297a57a5a743894a0e4a801fc3.yaml View File

@@ -1,4 +1,4 @@
last_checked: 1705023122
last_checked: 1705428561
data:
feed:
-


+ 10
- 0
grav-admin/user/js/registration/registration.vue View File

@@ -11,6 +11,16 @@ import Account from "./account.vue"

function create(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>



+ 12
- 5
skouter.go View File

@@ -4,6 +4,8 @@ import (
"os"
"os/exec"
"net/http"
"net/http/httputil"
"net/url"
"net/mail"
"log"
"sync"
@@ -215,7 +217,8 @@ type Endpoint func (http.ResponseWriter, *sql.DB, *http.Request)
var (
regexen = make(map[string]*regexp.Regexp)
relock sync.Mutex
address = "127.0.0.1:8001"
address = "localhost:8001"
mainAddress = "localhost:8002"
)

var paths = map[string]string {
@@ -2537,8 +2540,7 @@ func api(w http.ResponseWriter, r *http.Request) {
r.Method == http.MethodGet && guard(r, 1):
getUser(w, db, r)
case match(p, "/api/user", &args) &&
r.Method == http.MethodPost &&
guard(r, 1):
r.Method == http.MethodPost:
createUser(w, db, r)
case match(p, "/api/user", &args) &&
r.Method == http.MethodPatch &&
@@ -2639,7 +2641,7 @@ func route(w http.ResponseWriter, r *http.Request) {
page = pages[ "terms" ]
case match(p, "/app", &args):
page = pages[ "app" ]
default:
default:
http.NotFound(w, r)
return
}
@@ -2648,11 +2650,16 @@ func route(w http.ResponseWriter, r *http.Request) {
}

func serve() {

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.HandleFunc("/api/", api)
http.HandleFunc("/", route)
http.HandleFunc("/app", route)
http.Handle("/", httputil.NewSingleHostReverseProxy(proxy))
log.Fatal(http.ListenAndServe(address, nil))
}



Loading…
Cancel
Save