-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
fa77a13
commit 71ef377
Showing
34 changed files
with
298 additions
and
135 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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import 'package:dox_app/config/app.dart'; | ||
import 'package:dox_app/services/database_service.dart'; | ||
import 'package:dox_app/config/postgres.dart'; | ||
import 'package:dox_core/dox_core.dart'; | ||
import 'package:dox_migration/dox_migration.dart'; | ||
|
||
void main() async { | ||
/// Initialize Dox | ||
Dox().initialize(appConfig); | ||
|
||
/// run database migration before starting server | ||
await DatabaseService().migrate(); | ||
/// Run database migration before starting server. | ||
/// Since Migration need to process only once, | ||
/// it do not required to register in services. | ||
await Migration().migrate(postgresEndpoint); | ||
|
||
/// start dox http server | ||
/// Start dox http server | ||
await Dox().startServer(); | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import 'package:dox_app/models/user/user.model.dart'; | ||
import 'package:dox_app/app/http/serializers/user.serializer.dart'; | ||
import 'package:dox_app/app/models/user/user.model.dart'; | ||
import 'package:dox_auth/dox_auth.dart'; | ||
import 'package:dox_core/dox_core.dart'; | ||
import 'package:dox_core/utils/logger.dart'; | ||
|
||
class AuthController { | ||
Future<dynamic> login(DoxRequest req) async { | ||
|
@@ -25,7 +27,6 @@ class AuthController { | |
|
||
Future<dynamic> register(DoxRequest req) async { | ||
User user = User(); | ||
user.debug(true); | ||
user.name = 'AJ'; | ||
user.email = '[email protected]'; | ||
user.password = Hash.make('password'); | ||
|
@@ -34,9 +35,10 @@ class AuthController { | |
} | ||
|
||
Future<dynamic> user(DoxRequest req) async { | ||
if (req.auth?.isLoggedIn() == true) { | ||
return req.auth?.user(); | ||
IAuth? auth = req.auth; | ||
if (auth?.isLoggedIn() == true) { | ||
Logger.info('${auth?.user<User>()?.name} is logged in'); | ||
return UserSerializer(auth?.user()); | ||
} | ||
throw UnAuthorizedException(message: 'reach to controller'); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...lib/http/controllers/blog.controller.dart → ...app/http/controllers/blog.controller.dart
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
File renamed without changes.
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,8 @@ | ||
import 'package:dox_core/dox_core.dart'; | ||
|
||
class ResponseHandler extends ResponseHandlerInterface { | ||
@override | ||
DoxResponse handle(DoxResponse res) { | ||
return res; | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...ib/http/middleware/custom.middleware.dart → ...pp/http/middleware/custom.middleware.dart
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
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
packages/dox-app/lib/app/http/serializers/user.serializer.dart
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 @@ | ||
import 'package:dox_core/dox_core.dart'; | ||
|
||
import '../../../app/models/user/user.model.dart'; | ||
|
||
class UserSerializer extends Serializer<User> { | ||
UserSerializer(super.data); | ||
|
||
@override | ||
Map<String, dynamic> convert(User m) { | ||
return <String, dynamic>{}; | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...x-app/lib/http/services/blog.service.dart → ...p/lib/app/http/services/blog.service.dart
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
4 changes: 2 additions & 2 deletions
4
...s/dox-app/lib/models/blog/blog.model.dart → ...x-app/lib/app/models/blog/blog.model.dart
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
2 changes: 1 addition & 1 deletion
2
...dox-app/lib/models/blog/blog.model.g.dart → ...app/lib/app/models/blog/blog.model.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...p/lib/models/category/category.model.dart → ...b/app/models/category/category.model.dart
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
2 changes: 1 addition & 1 deletion
2
...lib/models/category/category.model.g.dart → ...app/models/category/category.model.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...dox-app/lib/models/user/user.model.g.dart → ...app/lib/app/models/user/user.model.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
import 'package:dox_websocket/dox_websocket.dart'; | ||
|
||
class BlogController { | ||
void index(WebsocketEmitter emitter, dynamic message) async { | ||
/// write your logic here | ||
} | ||
} |
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 |
---|---|---|
@@ -1,51 +1,80 @@ | ||
import 'package:dox_app/app/http/handler.dart'; | ||
import 'package:dox_app/config/cache.dart'; | ||
import 'package:dox_app/config/cors.dart'; | ||
import 'package:dox_app/config/logger.dart'; | ||
import 'package:dox_app/config/services.dart'; | ||
import 'package:dox_app/config/storage.dart'; | ||
import 'package:dox_app/http/handler.dart'; | ||
import 'package:dox_app/http/requests/blog.request.dart'; | ||
import 'package:dox_app/routes/api.dart'; | ||
import 'package:dox_app/routes/web.dart'; | ||
import 'package:dox_app/routes/websocket.dart'; | ||
import 'package:dox_core/dox_core.dart'; | ||
|
||
AppConfig appConfig = AppConfig( | ||
/// application key | ||
appKey: Env.get('APP_KEY'), | ||
/// Application secret key | ||
/// ------------------------------- | ||
/// This key is use to encrypt/decrypt the data such as cache and cookies. | ||
/// Make sure to keep the `APP_KEY` as an environment variable and secure. | ||
/// | ||
/// Note: Changing the application key for an existing app will make all | ||
/// the cookies and cache invalid and also the existing encrypted data | ||
/// will not be decrypted. | ||
appKey: Env.get<String>('APP_KEY'), | ||
|
||
/// application server port | ||
serverPort: int.parse(Env.get('APP_PORT', 3000)), | ||
/// Server port | ||
/// ------------------------------- | ||
/// App will be running on this port. | ||
serverPort: Env.get<int>('APP_PORT', 3000), | ||
|
||
/// total multi-thread isolate to run | ||
totalIsolate: 6, | ||
/// Total isolate (multi thread) | ||
/// ------------------------------- | ||
/// Total isolate to run the application. | ||
/// Depending on your machine CPU and RAM, you can adjust the the number | ||
/// of isolates. The more isolate application have, the more it can handle | ||
/// concurrency requests. | ||
totalIsolate: Env.get<int>('APP_TOTAL_ISOLATE', 6), | ||
|
||
/// global middleware | ||
globalMiddleware: <dynamic>[], | ||
/// Form requests | ||
/// ------------------------------- | ||
/// Register form request to dox in order to inject into the controller. | ||
/// Example, | ||
/// { | ||
/// BlogRequest : () => BlogRequest(), | ||
/// UserRequest : () => UserRequest(), | ||
/// } | ||
formRequests: <Type, FormRequest Function()>{}, | ||
|
||
/// form requests | ||
formRequests: <Type, FormRequest Function()>{ | ||
BlogRequest: () => BlogRequest(), | ||
}, | ||
/// Global middleware | ||
/// ------------------------------- | ||
/// By registering global middleware here, | ||
/// middleware will be applied to all the routes. | ||
globalMiddleware: <dynamic>[ | ||
LogMiddleware(enabled: true), | ||
], | ||
|
||
/// routers | ||
/// Routers | ||
/// ------------------------------- | ||
/// Register routers to create route to dox framework. | ||
routers: <Router>[ | ||
WebRouter(), | ||
ApiRouter(), | ||
WebsocketRouter(), | ||
], | ||
|
||
/// response handler | ||
/// Response handler | ||
responseHandler: ResponseHandler(), | ||
|
||
/// service to run on multithread server | ||
services: services, | ||
/// Cache driver configuration | ||
cache: cache, | ||
|
||
/// File storage driver configuration | ||
fileStorage: storage, | ||
|
||
/// cors configuration | ||
/// Cors configuration | ||
cors: cors, | ||
|
||
/// cache driver configuration | ||
cache: cache, | ||
/// Service to run on multithread server | ||
services: services, | ||
|
||
/// file storage driver configuration | ||
fileStorage: storage, | ||
/// logger configuration | ||
logger: logger, | ||
); |
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 |
---|---|---|
@@ -1,3 +1,61 @@ | ||
import 'package:dox_core/dox_core.dart'; | ||
|
||
CORSConfig cors = CORSConfig(); | ||
CORSConfig cors = CORSConfig( | ||
/// Enabled | ||
/// ------------------------------- | ||
/// A boolean to enable or disable CORS integration. | ||
/// Setting to true will enable the CORS for all HTTP request. | ||
enabled: false, | ||
|
||
/// Origin | ||
/// ------------------------------- | ||
/// Set a list of origins to be allowed for `Access-Control-Allow-Origin`. | ||
/// The value can be one of the following: | ||
/// Array : An array of allowed origins. | ||
/// String : Comma separated list of allowed origins. | ||
/// String (*) : A wildcard (*) to allow all request origins. | ||
origin: '*', | ||
|
||
/// Methods | ||
/// ------------------------------- | ||
/// Set a list of origins to be allowed for `Access-Control-Request-Method`. | ||
/// The value can be one of the following: | ||
/// Array : An array of request methods. | ||
/// String : Comma separated list of request methods. | ||
/// String (*) : A wildcard (*) to allow all request methods. | ||
methods: '*', | ||
|
||
/// Headers | ||
/// ------------------------------- | ||
/// Set a list of origins to be allowed for `Access-Control-Allow-Headers`. | ||
/// The value can be one of the following: | ||
/// Array : An array of allowed headers. | ||
/// String : Comma separated list of allowed headers. | ||
/// String (*) : A wildcard (*) to allow all request headers. | ||
headers: '*', | ||
|
||
/// Expose Headers | ||
/// ------------------------------- | ||
/// Set a list of origins to be allowed for `Access-Control-Expose-Headers`. | ||
/// The value can be one of the following: | ||
/// Array : An array of expose headers. | ||
/// String : Comma separated list of expose headers. | ||
exposeHeaders: <String>[ | ||
'cache-control', | ||
'content-language', | ||
'content-type', | ||
'expires', | ||
'last-modified', | ||
'pragma', | ||
], | ||
|
||
/// Credentials | ||
/// ------------------------------- | ||
/// Toggle `Access-Control-Allow-Credentials` header. | ||
credentials: true, | ||
|
||
/// MaxAge | ||
/// ------------------------------- | ||
/// Define `Access-Control-Max-Age` header in seconds. | ||
maxAge: 90, | ||
); |
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,24 @@ | ||
import 'package:dox_core/dox_core.dart'; | ||
|
||
LoggerConfig logger = LoggerConfig( | ||
/// Application name | ||
/// ------------------------------- | ||
/// The name of the application you want to add to the log. | ||
name: Env.get('APP_NAME'), | ||
|
||
/// Toggle logger | ||
/// ------------------------------- | ||
/// Enable or disable logger in application. | ||
enabled: true, | ||
|
||
/// Logging level | ||
/// ------------------------------- | ||
/// The level from which you want the logger to flush logs. | ||
level: Env.get('LOG_LEVEL', 'info'), | ||
|
||
/// Pretty print | ||
/// ------------------------------- | ||
/// It is highly advised NOT to use `prettyPrint` in production, since it | ||
/// can have huge impact on performance. | ||
prettyPrint: Env.get('APP_ENV') == 'development', | ||
); |
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,34 @@ | ||
import 'package:dox_core/dox_core.dart'; | ||
import 'package:postgres_pool/postgres_pool.dart'; | ||
|
||
PgEndpoint postgresEndpoint = PgEndpoint( | ||
/// database host | ||
host: Env.get('DB_HOST', 'localhost'), | ||
|
||
/// database port | ||
port: Env.get<int>('DB_PORT', 5432), | ||
|
||
/// database name | ||
database: Env.get('DB_NAME', 'dox'), | ||
|
||
/// database username | ||
username: Env.get('DB_USERNAME', 'postgres'), | ||
|
||
/// database password | ||
password: Env.get('DB_PASSWORD', 'postgres'), | ||
); | ||
|
||
/// postgres pool connection configuration | ||
PgPool pool = PgPool( | ||
postgresEndpoint, | ||
|
||
/// postgres setting | ||
settings: PgPoolSettings() | ||
|
||
/// The maximum duration a connection is kept open. | ||
/// New sessions won't be scheduled after this limit is reached. | ||
..maxConnectionAge = Duration(hours: 1) | ||
|
||
/// The maximum number of concurrent sessions. | ||
..concurrency = 10, | ||
); |
Oops, something went wrong.