Comments (2)
Hi there, apologies for the long delay.
The Koa framework works by essentially wrapping the underlying Node.js IncomingMessage
and ServerResponse
objects in a ctx
variable that's passed throughout the middleware during a particular request. This library isn't doing anything particularly novel that can't be easily extended to other web frameworks (or just a regular Node.js http
server):
- parsing the request URL, method, body, and headers
- setting the response body and headers
The biggest difference between operating on the raw req
and res
objects throughout this library is that we take advantage of the Koa context state to pass information between methods during the lifetime of a single request. In particular, we use ctx.state
for things like
- Setting the CalDAV URLs for the request, such as principal and calendar URLs
- Setting the parsed URL parameters
- Setting the authenticated user from the application
To extend this library for use in other frameworks, it'd involve refactoring all the uses of ctx
to either
A) operate on the raw req
and res
objects, or
B) create a framework-agnostic object that each web framework populates based on its own API, is populated by the functions in the library, and is finally passed back to the web framework to set the response values
Option B is probably preferable since we'd then be able to pass arbitrary information throughout the library, basically emulating the Koa context state behavior.
from caldav-adapter.
I would really like to use this package and I'll look into how to separate the HTTP framework specific stuff from the "core" functionality. When the "core" has a clear API it would be easier to create glue code for different HTTP frameworks.
EDIT: So I have noticed that the koa ctx is used consistently throughout the codebase. This might make it possible to stub that instance and have that interact with express equivalents.
These are ctx properties I have found in the codebase. Not all require stubbing.
ctx.body
ctx.get
ctx.method.toLowerCase
ctx.redirect
ctx.req
ctx.request.body
ctx.request.ical
ctx.request.type
ctx.request.type.includes
ctx.request.xml
ctx.request.xml.documentElement.localName
ctx.response.set
ctx.set
ctx.state.caldav
ctx.state.calendarHomeUrl
ctx.state.calendarUrl
ctx.state.params
ctx.state.params.calendarId
ctx.state.params.eventId
ctx.state.params.principalId
ctx.state.principalRootUrl
ctx.state.principalUrl
ctx.state.user
ctx.state.user.principalId
ctx.state.user.principalName
ctx.status
ctx.url
ctx.url.match
ctx.url.toLowerCase
Another idea is to spawn a process with a certain port number and proxy the requests in express to that localhost process. Might be less work to get that working.
from caldav-adapter.
Related Issues (11)
- Which clients has this been tested with? HOT 2
- Adapt line folding to cover surrogate pairs HOT 4
- CardDAV support HOT 2
- Tests and Compatibility Documentation (CardDAV/CalDAV RFC Support) HOT 26
- how to run? HOT 30
- ETag with Android HOT 4
- Allday events not working properly HOT 2
- Question: setting macOS HOT 1
- getEventsByDate seems to have not the correct response for iCal HOT 4
- xBuild multistatus handles empty responses incorrectly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from caldav-adapter.