Skip to content

Commit

Permalink
Merge pull request #43 from syumai/add-dem
Browse files Browse the repository at this point in the history
Add dem
  • Loading branch information
syumai authored Oct 2, 2019
2 parents 90b7b7d + 677a7f2 commit f38749a
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 14 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ interface HTTPResponse {

## Development

### Update module

- Please use [dem](https://github.com/syumai/dem)

```
dem update https://deno.land/[email protected]
```

### Testing

- `make test`
Expand Down
21 changes: 19 additions & 2 deletions constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
const { args } = Deno;
import { parse } from 'https://deno.land/std@v0.11.0/flags/mod.ts';
import { parse } from './vendor/https/deno.land/std/flags/mod.ts';

export const parsedArgs: {
p?: string;
port?: string;
[key: string]: any;
} = parse(args) || {};

export const defaultPort = parsedArgs.p || parsedArgs.port || '8080';
export const defaultPort = (() => {
const { p, port } = parsedArgs;
if (p) {
try {
return parseInt(p, 10);
} catch (e) {
// ignore parse error
}
}
if (port) {
try {
return parseInt(port, 10);
} catch (e) {
// ignore parse error
}
}
return 8080; // default port
})();
17 changes: 17 additions & 0 deletions dem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0.1.1",
"modules": [
{
"protocol": "https",
"path": "deno.land/std",
"version": "v0.19.0",
"files": [
"/flags/mod.ts",
"/http/server.ts",
"/strings/mod.ts",
"/testing/asserts.ts",
"/testing/mod.ts"
]
}
]
}
2 changes: 1 addition & 1 deletion example/form/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { cwd } = Deno;
import { app, get, post } from '../../mod.ts';
import { renderFile } from 'https://syumai.github.io/dejs/dejs.ts';
import { renderFile } from 'https://deno.land/x/dejs@0.3.1/mod.ts';

const templatePath = `${cwd()}/index.ejs`;

Expand Down
8 changes: 4 additions & 4 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { listen, stat, open, readAll } = Deno;
import {
Server,
ServerRequest,
} from 'http://deno.land/std@v0.11.0/http/server.ts';
} from './vendor/https/deno.land/std/http/server.ts';
import { Response, processResponse } from './response.ts';
import { ErrorCode, getErrorMessage } from './errors.ts';
import { Method, Handler, HandlerConfig } from './handler.ts';
Expand Down Expand Up @@ -156,9 +156,9 @@ export class App {
}

public async serve() {
const addr = `0.0.0.0:${this.port}`;
const listener = listen('tcp', addr);
console.log(`listening on http://${addr}/`);
const hostname = '0.0.0.0';
const listener = listen({ hostname, port: this.port });
console.log(`listening on http://${hostname}:${this.port}/`);
this.server = new Server(listener);
for await (const req of this.server) {
const method = req.method as Method;
Expand Down
2 changes: 1 addition & 1 deletion response.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Reader = Deno.Reader;
import { encode } from 'https://deno.land/std@v0.11.0/strings/mod.ts';
import { encode } from './vendor/https/deno.land/std/strings/mod.ts';

// HeaderMap is a type of response headers.
type HeaderMap =
Expand Down
6 changes: 3 additions & 3 deletions serve_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, runTests } from 'https://deno.land/std@v0.11.0/testing/mod.ts';
import { assertEquals } from 'https://deno.land/std@v0.11.0/testing/asserts.ts';
import { test, runTests } from './vendor/https/deno.land/std/testing/mod.ts';
import { assertEquals } from './vendor/https/deno.land/std/testing/asserts.ts';
import { App, get, post } from './mod.ts';
import { HandlerConfig, Method } from './handler.ts';
const { exit } = Deno;
Expand All @@ -14,7 +14,7 @@ interface RequestInit {
method?: string;
}

const testPort = '8376';
const testPort = 8376;
const host = `http://localhost:${testPort}`;

interface testCase {
Expand Down
6 changes: 3 additions & 3 deletions static_test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { test, runTests } from 'https://deno.land/std@v0.11.0/testing/mod.ts';
import { assertEquals } from 'https://deno.land/std@v0.11.0/testing/asserts.ts';
import { test, runTests } from './vendor/https/deno.land/std/testing/mod.ts';
import { assertEquals } from './vendor/https/deno.land/std/testing/asserts.ts';
import { App } from './mod.ts';
const { exit } = Deno;

const testPort = '8376';
const testPort = 8376;
const host = `http://localhost:${testPort}`;

const app = new App(testPort, true, 'testdata/static');
Expand Down
1 change: 1 addition & 0 deletions vendor/https/deno.land/std/flags/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'https://deno.land/[email protected]/flags/mod.ts';
1 change: 1 addition & 0 deletions vendor/https/deno.land/std/http/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'https://deno.land/[email protected]/http/server.ts';
1 change: 1 addition & 0 deletions vendor/https/deno.land/std/strings/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'https://deno.land/[email protected]/strings/mod.ts';
1 change: 1 addition & 0 deletions vendor/https/deno.land/std/testing/asserts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'https://deno.land/[email protected]/testing/asserts.ts';
1 change: 1 addition & 0 deletions vendor/https/deno.land/std/testing/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'https://deno.land/[email protected]/testing/mod.ts';

0 comments on commit f38749a

Please sign in to comment.