Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
Minds Backend - Engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
Minds
Minds Backend - Engine
Commits
de6fd8ed
Commit
de6fd8ed
authored
5 years ago
by
Mark Harding
Browse files
Options
Downloads
Patches
Plain Diff
(wip): Frontend rendering module
parent
75d495b6
No related branches found
No related tags found
Loading
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Core/Frontend/Manager.php
+145
-0
145 additions, 0 deletions
Core/Frontend/Manager.php
Core/Router.php
+12
-1
12 additions, 1 deletion
Core/Router.php
with
157 additions
and
1 deletion
Core/Frontend/Manager.php
0 → 100644
+
145
−
0
View file @
de6fd8ed
<?php
/**
* Serve frontend
*/
namespace
Minds\Core\Frontend
;
use
Minds\Core\Session
;
use
Minds\Core\Config
;
use
Minds\Core\Navigation
;
use
Minds\Core\Di\Di
;
use
Minds\Helpers
;
class
Manager
{
/** @var $socket */
private
$socket
;
/** @var string $host */
private
$host
=
'localhost'
;
/** @var int $port */
private
$port
=
9090
;
/**
* Server the request
* @param Request $request
* @return string
*/
public
function
serve
(
$request
)
{
$uri
=
$request
->
getRequestTarget
();
if
(
!
Session
::
isLoggedIn
())
{
// Only do SSR for logged out
try
{
return
$this
->
renderServerSide
(
$uri
);
}
catch
(
\Exception
$e
)
{
}
}
return
$this
->
renderClientSide
();
}
/**
* Render server side
* @param string $uri
* @return string
*/
private
function
renderServerSide
(
$uri
)
{
// Temp override memory
ini_set
(
'memory_limit'
,
'600M'
);
// Create the socket
$this
->
socket
=
socket_create
(
AF_INET
,
SOCK_STREAM
,
SOL_TCP
);
if
(
$this
->
socket
===
false
)
{
throw
new
\Exception
(
'Socket could not be created'
);
}
// Connect to the socket
socket_connect
(
$this
->
socket
,
$this
->
host
,
$this
->
port
);
$id
=
round
(
microtime
(
true
)
*
1000
);
// May not need this?
$send
=
json_encode
([
'id'
=>
$id
,
'url'
=>
$uri
,
'document'
=>
$this
->
getIndexFile
(),
]);
// Send the request
socket_write
(
$this
->
socket
,
$send
,
strlen
(
$send
));
// Read the result
$buffer
=
socket_read
(
$this
->
socket
,
(
1024
*
1024
)
*
200
);
// Decode JSON
$response
=
json_decode
(
$buffer
,
true
);
// Close socket
socket_close
(
$this
->
socket
);
return
$response
[
'html'
];
}
/**
* Render client side
* TODO: resupport i18n
* @return string
*/
private
function
renderClientSide
()
{
return
$this
->
getIndexFile
();
}
/**
* Collect the index file
* @return string
*/
private
function
getIndexFile
()
{
$dist
=
realpath
(
__MINDS_ROOT__
.
'/../front/dist'
);
$document
=
file_get_contents
(
$dist
.
'/en/index.php'
);
$document
=
str_replace
(
'<!-- MINDS_GLOBALS -->'
,
json_encode
(
$this
->
getWindowVariables
()),
$document
);
return
$document
;
}
/**
* Return window variables
* @return array
*/
protected
function
getWindowVariables
()
{
$minds
=
[
"MindsContext"
=>
'app'
,
"LoggedIn"
=>
Session
::
isLoggedIn
()
?
true
:
false
,
"Admin"
=>
Session
::
isAdmin
()
?
true
:
false
,
"cdn_url"
=>
Config
::
_
()
->
get
(
'cdn_url'
)
?:
Config
::
_
()
->
cdn_url
,
"cdn_assets_url"
=>
Config
::
_
()
->
get
(
'cdn_assets_url'
),
"site_url"
=>
Config
::
_
()
->
get
(
'site_url'
)
?:
Config
::
_
()
->
site_url
,
"cinemr_url"
=>
Config
::
_
()
->
get
(
'cinemr_url'
)
?:
Config
::
_
()
->
cinemr_url
,
"socket_server"
=>
Config
::
_
()
->
get
(
'sockets-server-uri'
)
?:
'ha-socket-io-us-east-1.minds.com:3030'
,
"navigation"
=>
Navigation\Manager
::
export
(),
"thirdpartynetworks"
=>
Di
::
_
()
->
get
(
'ThirdPartyNetworks\Manager'
)
->
availableNetworks
(),
'language'
=>
Di
::
_
()
->
get
(
'I18n'
)
->
getLanguage
(),
'languages'
=>
Di
::
_
()
->
get
(
'I18n'
)
->
getLanguages
(),
"categories"
=>
Config
::
_
()
->
get
(
'categories'
)
?:
[],
"stripe_key"
=>
Config
::
_
()
->
get
(
'payments'
)[
'stripe'
][
'public_key'
],
"recaptchaKey"
=>
Config
::
_
()
->
get
(
'google'
)[
'recaptcha'
][
'site_key'
],
"max_video_length"
=>
Config
::
_
()
->
get
(
'max_video_length'
),
"features"
=>
(
object
)
(
Config
::
_
()
->
get
(
'features'
)
?:
[]),
"blockchain"
=>
(
object
)
Di
::
_
()
->
get
(
'Blockchain\Manager'
)
->
getPublicSettings
(),
"sale"
=>
Config
::
_
()
->
get
(
'blockchain'
)[
'sale'
],
"last_tos_update"
=>
Config
::
_
()
->
get
(
'last_tos_update'
)
?:
time
(),
"tags"
=>
Config
::
_
()
->
get
(
'tags'
)
?:
[]
];
if
(
Session
::
isLoggedIn
())
{
$minds
[
'user'
]
=
Session
::
getLoggedinUser
()
->
export
();
$minds
[
'user'
][
'rewards'
]
=
!!
Session
::
getLoggedinUser
()
->
getPhoneNumberHash
();
$minds
[
'wallet'
]
=
array
(
'balance'
=>
Helpers\Counters
::
get
(
Session
::
getLoggedinUser
()
->
guid
,
'points'
,
false
));
}
return
$minds
;
}
}
This diff is collapsed.
Click to expand it.
Core/Router.php
+
12
−
1
View file @
de6fd8ed
...
...
@@ -36,6 +36,14 @@ class Router
'/checkout'
=>
'\\Minds\\Controllers\\checkout'
,
);
/** @var Manager $frontendManager */
private
$frontendManager
;
public
function
__construct
(
$frontendManager
=
null
)
{
$this
->
frontendManager
=
$frontendManager
?:
new
Frontend\Manager
;
}
/**
* Route the pages
* (fallback to elgg page handler if we fail).
...
...
@@ -143,7 +151,9 @@ class Router
}
if
(
!
$this
->
legacyRoute
(
$uri
))
{
(
new
I18n
())
->
serveIndex
();
echo
$this
->
frontendManager
->
serve
(
$request
);
exit
;
// Terminate here
//(new I18n())->serveIndex();
}
return
null
;
...
...
@@ -206,4 +216,5 @@ class Router
{
return
self
::
$routes
=
array_merge
(
self
::
$routes
,
$routes
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment