forked from maxzod/palace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
186 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'dart:io'; | ||
import 'package:http_server/http_server.dart'; | ||
|
||
Future main() async { | ||
var staticFiles = VirtualDirectory('public'); | ||
staticFiles.allowDirectoryListing = true; | ||
|
||
if (true) { | ||
//! Change to false if you show listing page | ||
staticFiles.directoryHandler = (dir, request) { | ||
var indexUri = Uri.file(dir.path).resolve('index.html'); | ||
staticFiles.serveFile(File(indexUri.toFilePath()), request); | ||
}; | ||
} | ||
|
||
var server = await HttpServer.bind(InternetAddress.loopbackIPv4, 3000); | ||
await server.forEach(staticFiles.serveRequest); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:path/path.dart'; | ||
|
||
class PalaceLogger { | ||
static DateTime get dt => DateTime.now(); | ||
static Directory get logFolder => | ||
Directory(Directory.current.path + '\\logs\\'); | ||
static String get _fileName => | ||
join(logFolder.path + '${dt.year}-${dt.month}-${dt.day}.log'); | ||
|
||
static Future<void> e(Object e) async { | ||
if (await logFolder.exists()) { | ||
await File(_fileName).writeAsString( | ||
'\n ERROR: [${dt.toIso8601String()}] $e', | ||
mode: FileMode.append); | ||
} else { | ||
await Directory(logFolder.path).create(); | ||
await File(_fileName).writeAsString( | ||
'\n ERROR: [${dt.toIso8601String()}] $e', | ||
mode: FileMode.append); | ||
} | ||
} | ||
|
||
static Future<void> l(Object e) async { | ||
if (await logFolder.exists()) { | ||
await File(_fileName).writeAsString( | ||
'\n LOG: [${dt.toIso8601String()}] $e', | ||
mode: FileMode.append); | ||
} else { | ||
await Directory(logFolder.path).create(); | ||
await File(_fileName).writeAsString( | ||
'\n LOG: [${dt.toIso8601String()}] $e', | ||
mode: FileMode.append); | ||
} | ||
} | ||
|
||
static Future<void> i(Object e) async { | ||
if (await logFolder.exists()) { | ||
await File(_fileName).writeAsString( | ||
'\n INFO: [${dt.toIso8601String()}] $e', | ||
mode: FileMode.append); | ||
} else { | ||
await Directory(logFolder.path).create(); | ||
await File(_fileName).writeAsString( | ||
'\n INFO: [${dt.toIso8601String()}] $e', | ||
mode: FileMode.append); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
ERROR: [2021-04-03T07:24:19.910156] Something Critical Happened ! | ||
ERROR: [2021-04-03T07:24:29.434278] Something Critical Happened ! |
File renamed without changes.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<p>hey</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# **`Part of Queen Palace 🏰👑`** | ||
|
||
🚧 Palace Is Under Construction 🚧 👷 | ||
|
||
🔑 Gates Will Open ASAP | ||
|
||
✔️ Stay Safe | ||
|
||
👑 Stay inside the kingdom | ||
|
||
# take look at bin/main | ||
|
||
- to run use dart `bin/main.dart` | ||
- use `lighthouse` for `run` && `watch` for changes | ||
`lh bin/main.dart` | ||
- there is a lot to do you are welcome to help building your `palace` | ||
|
||
# example | ||
|
||
if you want to test your self clone and run `bin/main.dart` | ||
|
||
```dart | ||
Future<void> main(List<String> args) async { | ||
final palace = PalaceRouter(); | ||
palace.use(LoggerGuard()); | ||
palace.get('/greet_the_queen', (req, res) async { | ||
return res.json({'data': 'Long Live The Queen'}); | ||
}); | ||
/// start the `server` | ||
await openGates(palace); | ||
} | ||
``` | ||
|
||
## Core Parts | ||
|
||
## `Request` | ||
|
||
wrapper class around dart `HttpRequest` | ||
mostly will be getters to ease extracting values form the `HttpRequest` | ||
|
||
## `Response` | ||
|
||
wrapper class around dart `HttpResponse` | ||
will have functions ease the process of responding to the incoming requests | ||
|
||
## `PalaceGuard` | ||
|
||
abstract class with one function to execute before giving the http request for the handler witch meas if you responds to the request form any guards the requests will not reach the next guards or even the endpoint handler it self | ||
**if you response to the request you will be ending the request life cycle** | ||
|
||
- in case of ending | ||
|
||
## `PalaceRouter` | ||
|
||
to help you set routes and the handler for each route | ||
|
||
## `palace` | ||
|
||
the palace file contains only one function `openGates(PalaceRouter,{port})` which takes palace router and will start server | ||
wait for incoming requests | ||
transforming them to Request object | ||
find the right endpoint if not found will respond with 404 | ||
if exist will loop throw the guards and the endpoint handler then close the IO request | ||
|
||
## TODO | ||
|
||
- [x] configuration reader | ||
example | ||
`final port = config('port');` | ||
- [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters