Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
186526 committed Jul 19, 2024
1 parent fccf33d commit c216c0a
Show file tree
Hide file tree
Showing 34 changed files with 1,332 additions and 1,226 deletions.
82 changes: 41 additions & 41 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
{
"name": "Handlers.js Devlopment Container",
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "16-bullseye"
}
},
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"ms-vscode.vscode-typescript-next",
"oderwat.indent-rainbow",
"GitHub.copilot",
"redhat.vscode-yaml",
"ms-azuretools.vscode-docker"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "yarn install",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node",
"features": {
"git": "latest",
"docker-in-docker": {
"version": "latest",
"moby": true,
"dockerDashComposeVersion": "v1"
},
"rust": {
"version": "latest",
"profile": "minimal"
}
}
}
"name": "Handlers.js Devlopment Container",
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "16-bullseye"
}
},
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"ms-vscode.vscode-typescript-next",
"oderwat.indent-rainbow",
"GitHub.copilot",
"redhat.vscode-yaml",
"ms-azuretools.vscode-docker"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "yarn install",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node",
"features": {
"git": "latest",
"docker-in-docker": {
"version": "latest",
"moby": true,
"dockerDashComposeVersion": "v1"
},
"rust": {
"version": "latest",
"profile": "minimal"
}
}
}
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 4
}
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"compile-hero.disable-compile-files-on-did-save-code": true,
"deno.enable": false,
"editor.formatOnSave": true,
}
"editor.formatOnSave": true
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
> Handlers.js is a unified and lightweight web application framework for multiple platforms.
```ts
import handlerJS from "handlers.js";
import handlerJS from 'handlers.js';

const App = new handlerJS();

App.binding(
"/",
App.create("ANY", async () => "Hello World!")
'/',
App.create('ANY', async () => 'Hello World!'),
);

App.useMappingAdapter();
Expand Down
254 changes: 127 additions & 127 deletions demo/errorHandler.ts

Large diffs are not rendered by default.

120 changes: 57 additions & 63 deletions demo/index.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,71 @@
import {
rootRouter,
method,
handler,
route,
response,
} from "../index";
import errorHandler from "./errorHandler";
import { rootRouter, method, handler, route, response } from '../index';
import errorHandler from './errorHandler';

const App = new rootRouter<any, any>();

App.binding(
"/(.*)",
new handler("ANY", [
async (request, response) => {
console.log(request);
return undefined;
},
])
'/(.*)',
new handler('ANY', [
async (request, response) => {
console.log(request);
return undefined;
},
]),
);

App.binding(
"/",
App.create(
"ANY",
(): Promise<string> =>
new Promise(() => {
console.log("Hello World!");
throw new response("Hello World!");
})
)
'/',
App.create(
'ANY',
(): Promise<string> =>
new Promise(() => {
console.log('Hello World!');
throw new response('Hello World!');
}),
),
).binding(
"/(.*)",
App.create(
"ANY",
(): Promise<string> =>
new Promise((resolve) => {
resolve("Hello World?")
})
)
'/(.*)',
App.create(
'ANY',
(): Promise<string> =>
new Promise((resolve) => {
resolve('Hello World?');
}),
),
);

App.route("/v1/(.*)")
.add(
new route(
["/echo", "/echo/(.*)"],
[
new handler(method["GET"], [
async (requestMessage, responseMessage) => {
responseMessage = responseMessage ?? new response("");
responseMessage?.headers.set("Hello", "World");
responseMessage.body = requestMessage.url.pathname;
return responseMessage;
},
]),
new handler(method["POST"], [
async (requestMessage, responseMessage) => {
responseMessage = responseMessage ?? new response("");
responseMessage.body = requestMessage.body;
return responseMessage;
},
]),
]
)
)
.binding(
"/error",
App.create(method["ANY"], async () => {
throw new Error("Nothing will happen here.");
})
)
.useErrorResponder(errorHandler);
App.route('/v1/(.*)')
.add(
new route(
['/echo', '/echo/(.*)'],
[
new handler(method['GET'], [
async (requestMessage, responseMessage) => {
responseMessage = responseMessage ?? new response('');
responseMessage?.headers.set('Hello', 'World');
responseMessage.body = requestMessage.url.pathname;
return responseMessage;
},
]),
new handler(method['POST'], [
async (requestMessage, responseMessage) => {
responseMessage = responseMessage ?? new response('');
responseMessage.body = requestMessage.body;
return responseMessage;
},
]),
],
),
)
.binding(
'/error',
App.create(method['ANY'], async () => {
throw new Error('Nothing will happen here.');
}),
)
.useErrorResponder(errorHandler);

App.useMappingAdapter();
App.listen(8080);

export default App;
export default App;
16 changes: 8 additions & 8 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { rootRouter } from "./src/router";
import { rootRouter } from './src/router';

export { handler } from "./src/handler";
export { route } from "./src/route";
export { router } from "./src/router";
export { methodENUM as method } from "./src/interface/method";
export { response } from "./src/interface/response";
export { request } from "./src/interface/request";
export * as platformAdapater from "./src/platform/export";
export { handler } from './src/handler';
export { route } from './src/route';
export { router } from './src/router';
export { methodENUM as method } from './src/interface/method';
export { response } from './src/interface/response';
export { request } from './src/interface/request';
export * as platformAdapater from './src/platform/export';

export { rootRouter };
export default rootRouter;
Loading

0 comments on commit c216c0a

Please sign in to comment.