Repository navigation
Expand file tree
/
Copy pathserver.php
More file actions
54 lines (40 loc) · 1.56 KB
/
Copy pathserver.php
File metadata and controls
54 lines (40 loc) · 1.56 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
<?php
require 'vendor/autoload.php';
use vennv\vapm\express\Express;
use vennv\vapm\simultaneous\Async;
session_start();
$express = new Express();
$app = $express->getApplication();
// This is a simple example of how to use the router
$router = $express->router(['mergeParams' => true]);
$childRouter1 = $express->router(['mergeParams' => true]);
$childRouter2 = $express->router(['mergeParams' => true]);
// Set the path to public folder of your website
$app->setPath(__DIR__ . '/website');
$app->use($app->static());
$app->use($app->json());
$childRouter2->get('/hello-name/:age', function ($request, $response) {
$params = $request->params;
return $response->send('Your name is ' . $params['name'] . ' and your age is ' . $params['age']);
});
$childRouter1->use('/info', $childRouter2);
$childRouter1->use('/hello-name/:name', function ($request, $response, $next) {
return $next();
});
$app->use('/router', $childRouter1);
$app->post('/login', function ($request, $response) {
return new Async(function () use ($request, $response) {
Async::await($response->active('/index.php'));
Async::await($response->redirect('/'));
});
});
$app->get('/', function ($request, $response) {
return $response->render('/index.php');
});
$app->get('/other', function ($request, $response) {
return $response->render('/other.html');
});
// example: http://127.0.0.1:8080/router/get-name/Nam/info/get-age/16
$app->listen(8080, function () {
echo 'Server is running on port 8080' . PHP_EOL;
});