Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #80 from U-ways/#79-path-utlis
Browse files Browse the repository at this point in the history
#79 path utlis
  • Loading branch information
u-ways authored Oct 8, 2020
2 parents c371442 + b723090 commit de32e75
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 6 deletions.
10 changes: 10 additions & 0 deletions backend/choppa.lock.json → backend/deps.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@
"https://deno.land/std@0.71.0/_util/assert.ts": "e1f76e77c5ccb5a8e0dbbbe6cce3a56d2556c8cb5a9a8802fc9565af72462149",
"https://deno.land/std@0.71.0/node/_utils.ts": "9fdd38e53754fc7e4fc38ab472a56be9ef3ce32c3503ac7b84ca1e0f563f69fa",
"https://deno.land/std@0.71.0/node/events.ts": "00fb524c3b10fc1a55f292c26dc6c949b8a31ac6d51c0db0c3a47ff13d2c46d4",
"https://deno.land/std@0.73.0/_util/assert.ts": "e1f76e77c5ccb5a8e0dbbbe6cce3a56d2556c8cb5a9a8802fc9565af72462149",
"https://deno.land/std@0.73.0/path/_constants.ts": "aba480c4a2c098b6374fdd5951fea13ecc8aaaf8b8aa4dae1871baa50243d676",
"https://deno.land/std@0.73.0/path/_interface.ts": "67b276380d297a7cedc3c17f7a0bf122edcfc96a3e1f69de06f379d85ba0e2c0",
"https://deno.land/std@0.73.0/path/_util.ts": "7820a788b35c26dfc27ff329df12507fc0553ae92727009597046f6cf856b4fa",
"https://deno.land/std@0.73.0/path/common.ts": "e4ec66a7416d56f60331b66e27a8a4f08c7b1cf48e350271cb69754a01cf5c04",
"https://deno.land/std@0.73.0/path/glob.ts": "54fea22f0f47dee07399d22e18a34a84eaf4b8a3771bbed96db43bbec71ef237",
"https://deno.land/std@0.73.0/path/mod.ts": "6de8885c2534757097818e302becd1cefcbc4c28ac022cc279e612ee04e8cfd1",
"https://deno.land/std@0.73.0/path/posix.ts": "7c2539b5d9e22b47f02ccc5b6ef11e3975a5c60f49d2241271eaa5936e6082a0",
"https://deno.land/std@0.73.0/path/separator.ts": "9dd15d46ff84a16e13554f56af7fee1f85f8d0f379efbbe60ac066a60561f036",
"https://deno.land/std@0.73.0/path/win32.ts": "47114c941681ecbabab4ec355cb41d525fb5a14175cc47a5c76fdc5eaee2685a",
"https://deno.land/x/media_types@v2.4.7/db.ts": "56a9deab286b6283e1df021d74ee3319353f27f7827716b6443427fff2fc6e24",
"https://deno.land/x/media_types@v2.4.7/deps.ts": "5eb8e569a0c1439f85f4a9888f8f3327b426c8b8f7ba55fdc1124d98d0e17390",
"https://deno.land/x/media_types@v2.4.7/mod.ts": "94141d7c415fcdad350fec9d36d77c18334efe25766db6f37d34709c896881ed",
Expand Down
3 changes: 2 additions & 1 deletion backend/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export {red, blue, gray, green, cyan, bold, yellow} from "https://deno.land/std@
export {Application, Context, Router, RouterContext, helpers, HttpError, Status} from "https://deno.land/x/oak@v6.2.0/mod.ts";
export {Pool} from "https://deno.land/x/postgres@v0.4.5/mod.ts";
export {PoolClient} from "https://deno.land/x/postgres@v0.4.5/client.ts";
export {applyGraphQL, gql, GQLError, ResolversProps} from "https://deno.land/x/oak_graphql@0.6.2/mod.ts"
export {applyGraphQL, gql, GQLError, ResolversProps} from "https://deno.land/x/oak_graphql@0.6.2/mod.ts"
export {resolve, dirname, fromFileUrl} from "https://deno.land/std@0.73.0/path/mod.ts";
10 changes: 8 additions & 2 deletions backend/scripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"env": {
"ENVIRONMENT": "development"
},
"lock": "./choppa.lock.json",
"lock": "./deps.lock.json",
"log": "info",
"tsconfig": "./tsconfig.json",
"watch": true
Expand All @@ -55,9 +55,15 @@
"env": {
"_comment": "Environment variables are set by the production environment"
},
"lock": "./choppa.lock.json",
"lock": "./deps.lock.json",
"tsconfig": "./tsconfig.json",
"watch": false
},
"test": {
"cmd": "deno test --allow-all tests/acceptance",
"tsconfig": "./tsconfig.json",
"desc": "Run Choppa backend acceptance tests",
"watch": false
}
},
"watcher": {
Expand Down
31 changes: 31 additions & 0 deletions backend/src/utils/path_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {dirname, fromFileUrl} from "../../deps.ts";

/**
* Get the relative (to file) working directory path from import meta.
* Usage Example:
*
* ```
* const __dirname = rwd(import.meta)
* // => ...choppa/backend/src/utils
* ```
*
* @param meta
*/
export function rwd(meta: ImportMeta): string {
return dirname(fromFileUrl(meta.url));
}

/**
* Get the relative filename path from import meta.
* Usage Example:
*
* ```
* const __filename = rfn(import.meta)
* // => ...choppa/backend/src/utils/path_utils.ts
* ```
*
* @param meta
*/
export function rfn(meta: ImportMeta): string {
return fromFileUrl(meta.url);
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import {assertEquals, plan, runTests, scenario, suite} from "../deps.ts";
import {Application} from "../../deps.ts";
import {Application, resolve} from "../../deps.ts";
import {port} from "../../config/choppa.config.ts";
import {generateAbortController, HOSTNAME} from "../utils/http_utils.ts";
import {staticRestServer} from "../../src/middlewares/static_server.ts";
import {rwd} from "../../src/utils/path_utils.ts";

plan("static_server.ts", () => {
const __dirname = rwd(import.meta);
const __resources = resolve(__dirname, "../resources")

suite("staticRestServer()", () => {
scenario("Can serve static content from a REST endpoint", async () => {
let result: Promise<string> = new Promise<string>(() => {})
let result: Promise<string> = new Promise<string>(() => {
})
const app = new Application();
const ac = generateAbortController();

app.use(staticRestServer(`${Deno.cwd()}/../resources`))
app.use(staticRestServer(__resources))

app.addEventListener("listen", async ({hostname, port}) => {
await fetch(`http://${hostname}:${port}/index.html`).then(res => result = res.text());
Expand Down
26 changes: 26 additions & 0 deletions backend/tests/deps.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"https://deno.land/std@0.63.0/_util/assert.ts": "e1f76e77c5ccb5a8e0dbbbe6cce3a56d2556c8cb5a9a8802fc9565af72462149",
"https://deno.land/std@0.63.0/async/deferred.ts": "ac95025f46580cf5197928ba90995d87f26e202c19ad961bc4e3177310894cdc",
"https://deno.land/std@0.63.0/async/delay.ts": "35957d585a6e3dd87706858fb1d6b551cb278271b03f52c5a2cb70e65e00c26a",
"https://deno.land/std@0.63.0/async/mod.ts": "39f2602a005805dd1e6b9da4ee5391b14d15e8fec4fa5494a6165c599911d746",
"https://deno.land/std@0.63.0/async/mux_async_iterator.ts": "1352b10a5cee1821a963eb8f4f05603bd7e25f8886eaf8d1888f4b416ddccdf5",
"https://deno.land/std@0.63.0/async/pool.ts": "a499691231d8c249f044f69d204b479ad3af7f115e0b37342829eff076bc2450",
"https://deno.land/std@0.63.0/bytes/mod.ts": "b1a149ac741728db00bda9ce1a2d044f248edd5ac95e708a6cc501bfd3adb4a7",
"https://deno.land/std@0.63.0/encoding/utf8.ts": "8654fa820aa69a37ec5eb11908e20b39d056c9bf1c23ab294303ff467f3d50a1",
"https://deno.land/std@0.63.0/fmt/colors.ts": "eb606cfb06e3f03a0222f09768a9701de2dd31c1fc8fa3a939137792a472962a",
"https://deno.land/std@0.63.0/http/_io.ts": "a6108623563611e901b1128ca91aca02982af552aa7c4f39f2240cf6e6cd9ac7",
"https://deno.land/std@0.63.0/http/http_status.ts": "0ecc0799a208f49452023b1b927106ba5a2c13cc6cf6666345db028239d554ab",
"https://deno.land/std@0.63.0/http/server.ts": "9f39d814950c741e0dcf0dfb9a046515f5fb342a62fbc28607c44ac5692e8a7e",
"https://deno.land/std@0.63.0/io/bufio.ts": "e76c5b7bf978a638aae6f62b87efde3ab7203b85902ce9b84ac8388c8c2bb104",
"https://deno.land/std@0.63.0/testing/asserts.ts": "1e9f87e0ecc456caa00a95f3345c5a7aeea0a4bf25c443a54341d9f6e36e5edf",
"https://deno.land/std@0.63.0/testing/diff.ts": "b685fb818c3527f0890628711934863672de2e94f01db421731654243f1eac8f",
"https://deno.land/std@0.63.0/textproto/mod.ts": "ebd84342f62216af1850279d32581c51d0958e36d477c6c26c961987e6240356",
"https://deno.land/x/rhum@v1.1.2/deps.ts": "fae73dec94d4400d25638600c2422fbe69dd220fcb9d804a8acc3e7a1570c84d",
"https://deno.land/x/rhum@v1.1.2/mod.ts": "987212dacfd09330cf599e37bc9d6a6f705923d41302cc8f7344c9cccc2853a8",
"https://deno.land/x/rhum@v1.1.2/src/interfaces.ts": "436a626741dc05469af55e9ce93225d026225b86cc8d0a4b4ddccb93e93f510d",
"https://deno.land/x/rhum@v1.1.2/src/mock_builder.ts": "b32adad486ec63995eb73fc690c4161771bf2a2b854dfb7e89e03340e20215ad",
"https://deno.land/x/rhum@v1.1.2/src/mocks/server_request.ts": "bfbada48e9b8965c97d1a177db733935ba961773000b31099b029de8b897c317",
"https://deno.land/x/rhum@v1.1.2/src/rhum_asserts.ts": "05db6de3215695a615b72cadb014524ff45706c01634bc0d07bb0db9571b17aa",
"https://deno.land/x/rhum@v1.1.2/src/test_case.ts": "c28798a802be705c2b5b0d1d54ed06bccdc7514912855b9ea6986321c4483644",
"https://deno.land/x/rhum@v1.1.2/src/types.ts": "0426124c9411c57f45edecf207aee0c3b76606371d678688c8513e1cf6508470"
}

0 comments on commit de32e75

Please sign in to comment.