I am quite a fan of ZEIT company and even more of their tool called Now.
I consider myself mainly as PHP developer, but I also like JavaScript. In these days static site generators are raising and I am totally into it.
So how to take advantage of static frontend but with dynamic backend written in PHP?
Since November 2019 it's simple as possible with ZEIT Now.
Milan Felix Šulc@xf3l1x@rauchg @drk @rjs @ionos_com @zeithq Hi @rjs.
Deploy static frontend with PHP files to @zeithq is pretty easy. We're using it daily.
I've prepared for you a demo. 🎄
You can reach me anytime. 👨🏻💻
bit.ly/2RF8cbh12:17 PM - 10 Dec 2019
Minimal project structure looks like this, you gonna need only 3 files.
project/
├── api/
│ ├── index.php
├── now.json
└── index.html
File index.html contains static frontend.
<html>
<head></head>
<body>
#
# Fetch data from /api/index.php using Fetch API
#
</body>
</html>
File api/index.php contains dynamic data or expose API endpoint.
<?php
header('conten-type: application/json');
echo json_encode(['tech' => 'ZEIT Now']);
File now.json setup deployment.
{
"functions": {
"api/index.php": {
"runtime": "now-php@0.0.7"
}
}
}
Finally you can call now
command and see what happened.
View this example on Github.
Top comments (0)