-
Notifications
You must be signed in to change notification settings - Fork 123
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
Set up server using express #21
Conversation
bin/server.ts
Outdated
import { SimpleRequestParser } from '../src/ldp/http/SimpleRequestParser'; | ||
import { SimpleResourceStore } from '../src/storage/SimpleResourceStore'; | ||
import { SimpleResponseWriter } from '../src/ldp/http/SimpleResponseWriter'; | ||
import { SimpleTargetExtractor } from '../src/ldp/http/SimpleTargetExtractor'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want a /src/index.ts
that exports them all, and then import them from there.
export { SimpleResponseWriter } from '../src/ldp/http/SimpleResponseWriter';
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Will also need this for Components.js.
bin/server.ts
Outdated
|
||
let port = 3000; | ||
|
||
if (process.argv.length >= 4 && process.argv[2] === '-p') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmmm 🙂 shall we immediately go for something more robust?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I didn't bother since this file should be very temporary, but it's true that such things have the tendency to then stay where they are
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just indicate it as such then?
bin/server.ts
Outdated
const authorizer = new SimpleAuthorizer(); | ||
|
||
// Will have to see how to best handle this | ||
const store = new SimpleResourceStore('http://localhost:3000/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably want to inject port in there too?
bin/server.ts
Outdated
httpServer.listen(port); | ||
|
||
// eslint-disable-next-line no-console | ||
console.log(`Running on port ${port}.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or process.stdout.print
(don't forget to add newline)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And actually, log the full URL (so it's clickable etc)
package.json
Outdated
@@ -2,12 +2,13 @@ | |||
"name": "@solid/community-server", | |||
"private": true, | |||
"version": "0.0.1", | |||
"main": "index.js", | |||
"main": "bin/server.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no, this should the bin
property. main
is the code entry point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That reminds me that we also need a typings
entry, like here: https://github.com/rubensworks/jsonld-context-parser.js/blob/master/package.json#L14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently the typings
field is ignored if you also have a files
field.
Also note that if your package.json includes the "files" property the "types" property will be ignored. In that case you need to pass your main declaration file to the "files" property as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL :-)
|
||
class SimpleHttpHandler extends HttpHandler { | ||
public async canHandle(): Promise<void> { | ||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen this a couple of times now, and always do a double-take.
Should we make this a Promise<boolean>
(but still make it the contract that it's either true
or an error)?
Or alternatively, rename this to ensureSupported
or whatever?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong opinions on this so can go any way for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is just return
possible actually? It's the undefined
that makes me think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linter then complains about having an unnecessary return statement. And if you completely remove it, it complains about having an empty function. :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest boolean
then; can be a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For completeness, the previous discussion where this changed to void was here
Comments were also added and URI generation takes slash into account
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing major to add next to @RubenVerborgh's review.
bin/server.ts
Outdated
import { SimpleRequestParser } from '../src/ldp/http/SimpleRequestParser'; | ||
import { SimpleResourceStore } from '../src/storage/SimpleResourceStore'; | ||
import { SimpleResponseWriter } from '../src/ldp/http/SimpleResponseWriter'; | ||
import { SimpleTargetExtractor } from '../src/ldp/http/SimpleTargetExtractor'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Will also need this for Components.js.
package.json
Outdated
@@ -2,12 +2,13 @@ | |||
"name": "@solid/community-server", | |||
"private": true, | |||
"version": "0.0.1", | |||
"main": "index.js", | |||
"main": "bin/server.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That reminds me that we also need a typings
entry, like here: https://github.com/rubensworks/jsonld-context-parser.js/blob/master/package.json#L14
Latest push should fix most issues (except handle function returning a boolean, that will be for later). I used the cors package now, but the allow-origin header still wasn't correct out of the box. By default it would always return |
Add changes of resource mapper
This allows setting up the (very basic) Solid server using
node bin/server.js
(with optionally-p port
). Until there is dependency injection this class also handles the linking of all the classes.I looked into Koa and the implementation would pretty much be 100% the same due to so little express code being used. Since there already was a dependency on express through another dependency I went for that one.
Some changes from the architecture:
CompositeAsyncHandler
.listen
function returns anhttp.Server
, makes testing much easier and makes it more similar to the actuallisten
interface ofhttp.Server
.Currently CORS is handled in the new server class. An
OptionOperationHandler
might be more in line with the rest of the architecture, but currently there is not really a clean way for such a handler to add headers to the output. I do think we will need this at some point so potentially this can be changed then.I looked into making the server extend
http.Server
to be consistent with that interface, but then many more overloads forlisten
are necessary, and making everything work with express is going to be much more of a hassle since there you only get a Server object when you call the listen function.This PR also fixed the identifier extraction and a bug in the
SimpleResourceStore
.