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

feat: add resource loader service (takes in paths and loads resources from it) #644

Merged
merged 11 commits into from
Jul 2, 2022

Conversation

crookse
Copy link
Member

@crookse crookse commented May 28, 2022

Closes #622

TODO

Summary

  • feat: adds ResourceLoaderService
  • feat: drash_resource property to Drash.Resource to help identify extended resources as a Drash.Resource
  • refactor: resources service config optional since they can be loaded via the ResourceLoaderService

Example Usage

If the folder structure looks like:

/path/to/project
  |-- /api_resources
  |    |-- orders_resource.ts
  |    |-- users_resource.ts
  |
  |-- /ssr_resources
  |    |-- home_page_resource.ts
  |    |-- contact_page_resource.ts
  |
  |-- app.ts
  |-- deps.ts
import { Drash, ResourceLoaderService } from "./deps.ts";

const resourceLoaderService = new ResourceLoaderService({
  paths_to_resources: [
    "./api_resources", // <--- Loads orders_resource and users_resource
    "./ssr_resources", // <--- Loads home_page_resource and contact_page_resource
  ],
});

const server = new Drash.Server({
  hostname: "localhost",
  port: 1447,
  protocol: "http",
  services: [resourceLoaderService],
});

server.run();

console.log(`Server running at ${server.address}.`);

@crookse crookse force-pushed the feat/resource-loader branch 2 times, most recently from 0be6038 to 92f7834 Compare May 29, 2022 02:13
@crookse crookse marked this pull request as ready for review May 29, 2022 02:13
@crookse crookse added the Type: Minor Merging this pull request results in a minor version increment label May 29, 2022
@crookse crookse force-pushed the feat/resource-loader branch 4 times, most recently from aff8820 to 1479fee Compare June 20, 2022 12:32
@crookse
Copy link
Member Author

crookse commented Jun 20, 2022

@Guergeiro @ebebbington , not sure what's going on with the windows test with trying to dynamically import

d:\a\drash\drash\tests\integration\services\resource_loader\resources\api\users_resource.ts

is that a thing on windows? lol. no rush on this. check when you're free.

@ebebbington
Copy link
Member

@crookse maybe use a combo of, or one of: new URL or import.meta.main?

continue;
}

const realPath = await Deno.realPath("./" + entry.path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the problem Windows paths don't work like that. I would advise using join.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was annoying 😮‍💨 : 36ec759

@crookse crookse merged commit 42e8d59 into main Jul 2, 2022
@crookse crookse deleted the feat/resource-loader branch July 2, 2022 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Minor Merging this pull request results in a minor version increment
Development

Successfully merging this pull request may close these issues.

feat: resource loader service
3 participants