Open goup-david opened 2 years ago
Hi. There is only one entrypoint to your app and it's in /api/index.php
according to your setup. Just place a little router to /api/index.php
and that should work.
Hi,
Isn't that what I already have in my vercel.json
file:
{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.4.0"
}
},
"routes": [
{ "src": "/(.*)", "dest": "/api/index.php" }
]
}
Well, can you prepare a MVP and share the code?
I've made the repo public see here: https://github.com/goup-david/testingphp
The vercel link is https://testingphp.vercel.app/
@f3l1x any chance you got a look at this? Would really appreciate the help
Your api/index.php
should contain something like:
if (str_starts_with($_SERVER['REQUEST_URI'], '/another-page') {
require __DIR__ . '/../another-page/index.php';
} else {
require __DIR__ . '/../index.php';
}
You must route that by your own. Because everything is pointing to your /api/index.php
.
How does that work with regards to style sheets? Within my code directory I have a file style.css, and within my index.php I include it:
However the file doesn't get called and if I go to /style.css it brings up the index.php page?
Take a look how Laravel devs solve it: https://github.com/juicyfx/vercel-php/issues/207#issuecomment-1007984117
Question
Struggling to load pages and files that are not the main index.php file.
This is my file structure:
Below is my
vercel.json
file:This is my
api/index.php
file:<?php include __DIR__ . '/../index.php'; ?>
This is my
index.php
file (in main route):My
another-page/index.php
file is:<h1>This better work</h1>
When I go to my server I get the following:
However when I go to /another-page, it doesn't load the correct
index.php
file.Any help is much appreciated.