-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
43 lines (30 loc) · 1.26 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
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Exception\HttpNotFoundException as NotFoundException;
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/config/db.php';
session_start();
$app = AppFactory::create();
$app->options('/{routes:.+}', function ($request, $response, $args) {
return $response;
});
$app->add(function ($request, $handler) {
$response = $handler->handle($request);
return $response
->withHeader('Access-Control-Allow-Origin', 'http://localhost:3000')
->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS')
->withHeader('Access-Control-Allow-Credentials', 'true');
});
$app->addBodyParsingMiddleware();
require __DIR__ . '/routes/auth.php';
require __DIR__ . '/routes/comments.php';
require __DIR__ . '/routes/blogs.php';
require __DIR__ . '/routes/votes.php';
$app->map(['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], '/{routes:.+}', function ($request, $response) {
throw new NotFoundException($request);
});
// Run application
$app->run();