Skip to content

Commit

Permalink
feat: Set up server using express
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimvh committed Jul 15, 2020
1 parent c53ab5e commit a9dc59b
Show file tree
Hide file tree
Showing 7 changed files with 1,439 additions and 101 deletions.
65 changes: 65 additions & 0 deletions bin/server.ts
@@ -0,0 +1,65 @@
import yargs from 'yargs';
import {
AcceptPreferenceParser,
AuthenticatedLdpHandler,
CompositeAsyncHandler,
ExpressHttpServer,
Operation,
ResponseDescription,
SimpleAuthorizer,
SimpleBodyParser,
SimpleCredentialsExtractor,
SimpleDeleteOperationHandler,
SimpleGetOperationHandler,
SimplePermissionsExtractor,
SimplePostOperationHandler,
SimpleRequestParser,
SimpleResourceStore,
SimpleResponseWriter,
SimpleTargetExtractor,
} from '..';

const { argv } = yargs
.usage('node ./bin/server.js [args]')
.options({
port: { type: 'number', alias: 'p', default: 3000 },
})
.help();

const { port } = argv;

// This is instead of the dependency injection that still needs to be added
const requestParser = new SimpleRequestParser({
targetExtractor: new SimpleTargetExtractor(),
preferenceParser: new AcceptPreferenceParser(),
bodyParser: new SimpleBodyParser(),
});

const credentialsExtractor = new SimpleCredentialsExtractor();
const permissionsExtractor = new SimplePermissionsExtractor();
const authorizer = new SimpleAuthorizer();

// Will have to see how to best handle this
const store = new SimpleResourceStore(`http://localhost:${port}/`);
const operationHandler = new CompositeAsyncHandler<Operation, ResponseDescription>([
new SimpleGetOperationHandler(store),
new SimplePostOperationHandler(store),
new SimpleDeleteOperationHandler(store),
]);

const responseWriter = new SimpleResponseWriter();

const httpHandler = new AuthenticatedLdpHandler({
requestParser,
credentialsExtractor,
permissionsExtractor,
authorizer,
operationHandler,
responseWriter,
});

const httpServer = new ExpressHttpServer(httpHandler);

httpServer.listen(port);

process.stdout.write(`Running at http://localhost:${port}/\n`);
76 changes: 76 additions & 0 deletions index.ts
@@ -0,0 +1,76 @@
// Authentication
export * from './src/authentication/Credentials';
export * from './src/authentication/CredentialsExtractor';
export * from './src/authentication/SimpleCredentialsExtractor';

// Authorization
export * from './src/authorization/Authorizer';
export * from './src/authorization/SimpleAuthorizer';

// LDP/HTTP
export * from './src/ldp/http/AcceptPreferenceParser';
export * from './src/ldp/http/BodyParser';
export * from './src/ldp/http/Patch';
export * from './src/ldp/http/PreferenceParser';
export * from './src/ldp/http/RequestParser';
export * from './src/ldp/http/ResponseWriter';
export * from './src/ldp/http/SimpleBodyParser';
export * from './src/ldp/http/SimpleRequestParser';
export * from './src/ldp/http/SimpleResponseWriter';
export * from './src/ldp/http/SimpleTargetExtractor';
export * from './src/ldp/http/TargetExtractor';

// LDP/Operations
export * from './src/ldp/operations/Operation';
export * from './src/ldp/operations/OperationHandler';
export * from './src/ldp/operations/ResponseDescription';
export * from './src/ldp/operations/SimpleDeleteOperationHandler';
export * from './src/ldp/operations/SimpleGetOperationHandler';
export * from './src/ldp/operations/SimplePostOperationHandler';

// LDP/Permissions
export * from './src/ldp/permissions/PermissionSet';
export * from './src/ldp/permissions/PermissionsExtractor';
export * from './src/ldp/permissions/SimplePermissionsExtractor';

// LDP/Representation
export * from './src/ldp/representation/BinaryRepresentation';
export * from './src/ldp/representation/NamedRepresentation';
export * from './src/ldp/representation/QuadRepresentation';
export * from './src/ldp/representation/Representation';
export * from './src/ldp/representation/RepresentationMetadata';
export * from './src/ldp/representation/RepresentationPreference';
export * from './src/ldp/representation/RepresentationPreferences';
export * from './src/ldp/representation/ResourceIdentifier';

// LDP
export * from './src/ldp/AuthenticatedLdpHandler';

// Server
export * from './src/server/ExpressHttpServer';
export * from './src/server/HttpHandler';
export * from './src/server/HttpRequest';
export * from './src/server/HttpResponse';

// Storage
export * from './src/storage/AtomicResourceStore';
export * from './src/storage/Conditions';
export * from './src/storage/Lock';
export * from './src/storage/RepresentationConverter';
export * from './src/storage/ResourceLocker';
export * from './src/storage/ResourceMapper';
export * from './src/storage/ResourceStore';
export * from './src/storage/SimpleResourceStore';

// Util/Errors
export * from './src/util/errors/HttpError';
export * from './src/util/errors/NotFoundHttpError';
export * from './src/util/errors/UnsupportedHttpError';
export * from './src/util/errors/UnsupportedMediaTypeHttpError';

// Util
export * from './src/util/AcceptParser';
export * from './src/util/AsyncHandler';
export * from './src/util/CompositeAsyncHandler';
export * from './src/util/TypedReadable';
export * from './src/util/Util';

0 comments on commit a9dc59b

Please sign in to comment.