Skip to content

Commit 964477f

Browse files
committed
Enhance Docker setup with watchexec for hot reloading and update Router to handle missing modifiedLines gracefully
1 parent 4f3f7a5 commit 964477f

File tree

5 files changed

+255
-6
lines changed

5 files changed

+255
-6
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ RUN apk add --no-cache $PHPIZE_DEPS git zip unzip linux-headers \
66
&& pecl install xdebug \
77
&& docker-php-ext-enable xdebug
88

9+
# Install watchexec for hot reloading
10+
RUN apk add --no-cache watchexec
11+
912
# Set working directory
1013
WORKDIR /app
1114

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ services:
1414
environment:
1515
- PORT=3010
1616
- PHP_ENV=development
17-
# Using PHP development server that auto-reloads when files change
18-
command: sh -c "php -S 0.0.0.0:3010 index.php"
17+
# Using watchexec for hot reloading when PHP files change
18+
command: sh -c "watchexec -e php -r -w . 'php -S 0.0.0.0:3010 index.php'"
1919
networks:
2020
- snorkell_network
2121

integeration_test/samples/sample1.json

Lines changed: 243 additions & 1 deletion
Large diffs are not rendered by default.

integeration_test/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424

2525
# write the json to a file in pretty format
2626
with open(f'{current_directory}/samples/sample1.json', 'w') as json_file:
27+
pass
2728
json.dump(response.json(), json_file, indent=4)
2829
print(response.text)

src/Router.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function handleRequest()
4747
private function handleHealthCheck()
4848
{
4949
http_response_code(200);
50-
echo json_encode(['status' => 'hello from php!', 'timestamp' => time()]);
50+
echo json_encode(['status' => 'hello from Php!', 'timestamp' => time()]);
5151
}
5252

5353
/**
@@ -68,7 +68,7 @@ private function handleParseRequest()
6868

6969
// Validate request data
7070
if (!$requestData || !isset($requestData['code']) ||
71-
!isset($requestData['modifiedLines']) || !isset($requestData['fileType'])) {
71+
!isset($requestData['fileType'])) {
7272
http_response_code(400);
7373
echo json_encode(['error' => 'Invalid request data']);
7474
return;
@@ -77,9 +77,12 @@ private function handleParseRequest()
7777
// Create parser and process code
7878
try {
7979
$parser = new CodeParser();
80+
// Set default empty string for modifiedLines if not provided
81+
$modifiedLines = isset($requestData['modifiedLines']) ? $requestData['modifiedLines'] : '';
82+
8083
$result = $parser->parseCode(
8184
$requestData['code'],
82-
$requestData['modifiedLines'],
85+
$modifiedLines,
8386
$requestData['fileType']
8487
);
8588

0 commit comments

Comments
 (0)