-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.php
59 lines (45 loc) · 1.8 KB
/
dev.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
// Development server. Contains certain routes that
// the production server doesn't need, as they're configured in Apache.
require_once __DIR__ . "/core.php";
require_once __DIR__ . "/router.php";
$_NODE = match($_SERVER['HTTP_HOST']) {
CMS_HOST => "cms",
HOST => "site",
default => die("Unknown host!")
};
function serve_file($path) {
$mime_type = parse_mime_type($path) ?? "text/html";
header("Content-Type: {$mime_type}");
include $path;
exit;
}
$requested_file = path_join(__DIR__, $_NODE, $path);
$requested_upload = path_join(STORE, $path);
switch(true) {
case is_file($requested_file) and is_builtin():
// Serve file as-is. Only applies to the development server,
// in production this will be handled by Apache directly.
serve_file($requested_file);
case is_file($requested_upload) and is_builtin():
// Serve (image) file as-is. Only applies to the development server,
// in production this will be handled by Apache directly.
serve_file($requested_upload);
// Serve RSS feeds. Again, only in development.
case route('@/rss.xml$@'): include __DIR__ . "/feeds/rss.php"; exit;
case route('@/atom.xml$@'): include __DIR__ . "/feeds/atom.php"; exit;
case route('@/feed.json$@'): include __DIR__ . "/feeds/json.php"; exit;
case route('@/sitemap.xml$@'): include __DIR__ . "/feeds/sitemap.php"; exit;
case route('@/robots.txt$@'): include __DIR__ . "/feeds/robots.php"; exit;
case route('@/endpoint/(\w+)$@'):
// Here be dragons.
// But it's development, so who cares. Nobody is gonna
// run the dev server in prod anyway. Right... right???!
include __DIR__ . "/endpoint/{$params[1]}.php";
exit;
default:
// Depending on the environment, run either the
// site or CMS router.
include __DIR__ . "/$_NODE/index.php";
exit;
}