Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize Middlewares #200

Closed
3 tasks done
Guergeiro opened this issue Apr 22, 2020 · 0 comments · Fixed by #204
Closed
3 tasks done

Standardize Middlewares #200

Guergeiro opened this issue Apr 22, 2020 · 0 comments · Fixed by #204
Assignees

Comments

@Guergeiro
Copy link
Member

Guergeiro commented Apr 22, 2020

Summary

What: Make server level middleware accept functions and drop current implementation.

Why: Keeping a standard for all middlewares (see #186).

Acceptance Criteria

  • Implement functionality for server handling
  • Make it asynchronous
  • Update tests (if necessary)

Example Pseudo Code (for implementation)

// ---------- Previous
class ServerMiddleware extends Drash.Http.Middleware {
    public run() {
        console.log(`server middleware with ${this.request}${this.response}`);
    }
}
const server = new Drash.Http.Server({
    resources: [HomeResource],
    middleware: {
        before_request: [ServerMiddleware],
        after_request: [ServerMiddleware]
    }
});

// ---------- Feature
function SyncServerMiddleware(req: any, response: Drash.Http.Response) {
    console.log(`server middleware with ${request}${response}`);
}
async function AsyncServerMiddleware(req: any, response: Drash.Http.Response) {
    console.log(`server middleware with ${request}${response}`);
}
const server = new Drash.Http.Server({
    resources: [HomeResource],
    middleware: {
        before_request: [SyncServerMiddleware],
        after_request: [AsyncServerMiddleware]
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant