-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
68 lines (62 loc) · 1.68 KB
/
index.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
60
61
62
63
64
65
66
67
68
<?php
require_once __DIR__ . '/vendor/autoload.php';
$router = new \Bramus\Router\Router();
$router -> get('/', function() {
// do something clever
if(file_exists("index.html")) {
echo file_get_contents("index.html");
}
else {
echo "index file not found.";
}
});
$router -> get('/js/index.js', function () {
// do something clever
if(file_exists("index.js")) {
echo file_get_contents("index.js");
}
else {
echo "index.js file not found.";
}
return $response;
});
$router -> post('/post/url', function() {
$serviceName = filter_input(INPUT_POST, "sel-service");
$longUrl = filter_input(INPUT_POST, "longUrl");
if(isset($serviceName) && isset($longUrl)) {
$key = file_get_contents("auth/key.txt");
$key = json_decode($key, true);
if($serviceName === "goo.gl") {
$config = array(
'service-name' => $serviceName,
'longUrl' => $longUrl,
'apiKey' => $key[$serviceName]
);
}
else if($serviceName === "bit.ly") {
$config = array(
'service-name' => $serviceName,
'longUrl' => $longUrl,
'apiKey' => $key[$serviceName]["apiKey"],
'login' => $key[$serviceName]["login"]
);
}
else {
$config = array(
'service-name' => $serviceName,
'longUrl' => $longUrl
);
}
$bundle = new \peter\components\serviceBundle\serviceBundle($config);
echo json_encode($bundle -> sendReq());
}
else {
echo "Oops ! no data input";
}
});
$router->set404(function() {
header('HTTP/1.1 404 Not Found');
// ... do something special here
echo file_get_contents("404.html");
});
$router -> run();