-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.php
More file actions
67 lines (55 loc) · 2.26 KB
/
Copy pathstart.php
File metadata and controls
67 lines (55 loc) · 2.26 KB
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
60
61
62
63
64
65
66
67
<?php
set_error_handler(function($severity, $message, $file, $line) {
throw new ErrorException($message, 0, $severity, $file, $line);
});
require('api/log.php');
require('api/http.php');
require('api/start/inspector.php');
require('api/start/repository.php');
require('api/start/handler.php');
$root = realpath(__DIR__);
$base = getenv('BASE');
$db = new SQLite3('db.sqlite');
$repository = Persistence\Repository::open($db);
$rootLogger = Log\ConsoleLogger::for('RootLogger');
$httpLogger = Log\ConsoleLogger::for('HttpLogger');
$request = Http\newRequest();
$response = Http\newResponse();
$router = new Http\Router($base, $httpLogger);
$router->add('GET', '/', Http\serveRedirect("{$base}/index.html"));
$router->add('POST', '/api/inspect', new Http\Handler\InspectPage());
$router->add('GET', '/api/users', new Http\Handler\ListUsers($repository));
$router->add('POST', '/api/users', new Http\Handler\CreateUser($repository));
$router->add('GET', '/api/pages', new Http\Handler\ListPages($repository));
$router->add('PUT', '/api/pages/[-_.~%a-zA-Z0-9]+', new Http\Handler\SavePage($repository));
$router->add('DELETE', '/api/pages/[-_.~%a-zA-Z0-9]+', new Http\Handler\DeletePage($repository));
foreach(array(
'/index.html' => 'app/start/index.html',
'/service-worker.js' => 'app/start/service-worker.js',
'/app/async.js' => 'app/async.js',
'/app/dom.js' => 'app/dom.js',
'/app/router.js' => 'app/router.js',
'/app/search.js' => 'app/search.js',
'/app/storage.js' => 'app/storage.js',
'/app/page.js' => 'app/start/page.js',
'/app/broker.js' => 'app/start/webext/broker.js',
'/app/accounts.js' => 'app/start/accounts.js',
'/app/tabs.js' => 'app/start/tabs.js',
'/app/presenter.js' => 'app/start/presenter.js',
'/app/repository.js' => 'app/start/repository.js',
'/app/syncmanager.js' => 'app/start/syncmanager.js',
'/app/views.js' => 'app/start/views.js',
'/app/styles.css' => 'app/start/styles.css',
) as $path => $file) {
$router->add('GET', $path, Http\serveFile("{$root}/{$file}"));
}
try {
if (!$router->apply($request, $response)) {
$response->setStatus(404);
}
} catch (Throwable $e) {
$rootLogger->error('uncaught {exception}', ['exception' => $e]);
$response->setStatus(500);
$response->setBodyAsText($e->getMessage());
}
?>