-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.php
More file actions
38 lines (30 loc) · 796 Bytes
/
index.php
File metadata and controls
38 lines (30 loc) · 796 Bytes
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
<?php
require('./vendor/autoload.php');
use Unic\App;
$app = new App();
// Set view directory path and view engine
$app->set('views', __DIR__ . '/views');
$app->set('view_engine', 'twig');
// Set public path and static files directory
$app->use($app->static('/', __DIR__ . '/public'));
// Routes
$app->get('/', function ($req, $res) {
$res->render('index.twig', [
'title' => 'Unic',
]);
});
$app->get('/api', function ($req, $res) {
$res->json([
'status' => "ok",
]);
});
// Error handler middleware
$app->use(function ($err, $req, $res, $next) {
$res->status(500)
->render('error.twig', [
'message' => $err->getMessage(),
'stack' => $err->getTraceAsString(),
'status' => 500,
]);
});
$app->start();