mirror of
https://github.com/rjNemo/deno_hello
synced 2026-06-06 10:06:40 +00:00
Compare commits
10 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48cf30f6e0 | ||
|
|
a25356dd68 | ||
|
|
75448f34b0 | ||
|
|
df159cc6cb | ||
|
|
4cb341715c | ||
|
|
ff16b10fd7 | ||
|
|
1acc1232ba | ||
|
|
8998c65967 | ||
|
|
b42c701f20 | ||
|
|
0f54f17f18 |
31 changed files with 214 additions and 215 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -26,3 +26,6 @@ Icon
|
|||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
.coverage
|
||||
.idea/
|
||||
2
.gitpod.yml
Normal file
2
.gitpod.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
tasks:
|
||||
- init: make
|
||||
8
.idea/.gitignore
vendored
8
.idea/.gitignore
vendored
|
|
@ -1,8 +0,0 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DenoSettings">
|
||||
<option name="useDeno" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="ruidy" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
<option name="PROJECT_TEST_RUNNER" value="pytest" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ourVersions">
|
||||
<value>
|
||||
<list size="2">
|
||||
<item index="0" class="java.lang.String" itemvalue="3.8" />
|
||||
<item index="1" class="java.lang.String" itemvalue="3.9" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/hello-server.iml" filepath="$PROJECT_DIR$/.idea/hello-server.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PrettierConfiguration">
|
||||
<option name="myRunOnSave" value="true" />
|
||||
<option name="myRunOnReformat" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectTasksOptions">
|
||||
<TaskOptions isEnabled="true">
|
||||
<option name="arguments" value="fmt" />
|
||||
<option name="checkSyntaxErrors" value="true" />
|
||||
<option name="description" />
|
||||
<option name="exitCodeBehavior" value="ERROR" />
|
||||
<option name="fileExtension" value="ts" />
|
||||
<option name="immediateSync" value="false" />
|
||||
<option name="name" value="deno" />
|
||||
<option name="output" value="" />
|
||||
<option name="outputFilters">
|
||||
<array />
|
||||
</option>
|
||||
<option name="outputFromStdout" value="false" />
|
||||
<option name="program" value="deno" />
|
||||
<option name="runOnExternalChanges" value="false" />
|
||||
<option name="scopeName" value="Project Files" />
|
||||
<option name="trackOnlyRoot" value="false" />
|
||||
<option name="workingDir" value="" />
|
||||
<envs />
|
||||
</TaskOptions>
|
||||
</component>
|
||||
</project>
|
||||
29
.vscode/settings.json
vendored
29
.vscode/settings.json
vendored
|
|
@ -1,14 +1,19 @@
|
|||
{
|
||||
"deno.enable": true,
|
||||
"deno.unstable": true,
|
||||
"deno.lint": true,
|
||||
"deno.import_intellisense_origins": {
|
||||
"https://deno.land": true
|
||||
},
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "denoland.vscode-deno"
|
||||
},
|
||||
"[typescriptreact]": {
|
||||
"editor.defaultFormatter": "denoland.vscode-deno"
|
||||
}
|
||||
"deno.enable": true,
|
||||
"deno.unstable": true,
|
||||
"deno.lint": true,
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "denoland.vscode-deno"
|
||||
},
|
||||
"[typescriptreact]": {
|
||||
"editor.defaultFormatter": "denoland.vscode-deno"
|
||||
},
|
||||
"files.eol": "\n",
|
||||
"files.trimTrailingWhitespace": true,
|
||||
"files.exclude": {
|
||||
"**/.git": true,
|
||||
"**/.DS_Store": true,
|
||||
"**/Thumbs.db": true,
|
||||
"**/.aleph": true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,25 @@
|
|||
# Contributing
|
||||
|
||||
When contributing to this repository, please first discuss the change you wish to make via issue,
|
||||
email, or any other method with the owners of this repository before making a change.
|
||||
When contributing to this repository, please first discuss the change you wish
|
||||
to make via issue, email, or any other method with the owners of this repository
|
||||
before making a change.
|
||||
|
||||
Please note we have a code of conduct, please follow it in all your interactions with the project.
|
||||
Please note we have a code of conduct, please follow it in all your interactions
|
||||
with the project.
|
||||
|
||||
## Pull Request Process
|
||||
|
||||
1. Ensure any install or build dependencies are removed before the end of the layer when doing a
|
||||
build.
|
||||
2. Update the README.md with details of changes to the interface, this includes new environment
|
||||
variables, exposed ports, useful file locations and container parameters.
|
||||
3. Increase the version numbers in any examples files and the README.md to the new version that this
|
||||
Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
|
||||
4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
|
||||
do not have permission to do that, you may request the second reviewer to merge it for you.
|
||||
1. Ensure any install or build dependencies are removed before the end of the
|
||||
layer when doing a build.
|
||||
2. Update the README.md with details of changes to the interface, this includes
|
||||
new environment variables, exposed ports, useful file locations and container
|
||||
parameters.
|
||||
3. Increase the version numbers in any examples files and the README.md to the
|
||||
new version that this Pull Request would represent. The versioning scheme we
|
||||
use is [SemVer](http://semver.org/).
|
||||
4. You may merge the Pull Request in once you have the sign-off of two other
|
||||
developers, or if you do not have permission to do that, you may request the
|
||||
second reviewer to merge it for you.
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
|
|
@ -23,9 +28,9 @@ Please note we have a code of conduct, please follow it in all your interactions
|
|||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
size, disability, ethnicity, gender identity and expression, level of
|
||||
experience, nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
### Our Standards
|
||||
|
||||
|
|
@ -55,11 +60,11 @@ Project maintainers are responsible for clarifying the standards of acceptable
|
|||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, or to ban temporarily or permanently any
|
||||
contributor for other behaviors that they deem inappropriate, threatening,
|
||||
offensive, or harmful.
|
||||
|
||||
### Scope
|
||||
|
||||
|
|
@ -76,8 +81,9 @@ Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|||
reported by contacting the project team at [ruidy.nemausat@gmail.com]. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
obligated to maintain confidentiality with regard to the reporter of an
|
||||
incident. Further details of specific enforcement policies may be posted
|
||||
separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
|
|
@ -85,8 +91,8 @@ members of the project's leadership.
|
|||
|
||||
### Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
|
|
|
|||
23
LICENSE.md
23
LICENSE.md
|
|
@ -2,20 +2,19 @@
|
|||
|
||||
Copyright (c) [2021] [Ruidy]
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
|
|
|||
12
Makefile
12
Makefile
|
|
@ -1,8 +1,12 @@
|
|||
.PHONY: cli
|
||||
cli:
|
||||
deno run cli.ts
|
||||
.PHONY: run
|
||||
run:
|
||||
deno run --allow-net server.ts
|
||||
deno run --watch --allow-net src/main.ts
|
||||
lint:
|
||||
deno lint --unstable
|
||||
test: tests
|
||||
tests:
|
||||
deno test --coverage --unstable
|
||||
deno test --coverage=.coverage --unstable
|
||||
deno coverage .coverage
|
||||
|
||||
.PHONY: cli run lint test tests
|
||||
28
README.md
28
README.md
|
|
@ -1,6 +1,8 @@
|
|||
[](https://gitpod.io/#https://github.com/rjNemo/deno_hello)
|
||||
|
||||
# Hello Server
|
||||
|
||||
Web app which returns the iconic Hello, World in various locales
|
||||
Web app which returns the iconic `Hello, World` in various locales.
|
||||
|
||||
## Features
|
||||
|
||||
|
|
@ -8,10 +10,13 @@ Web app which returns the iconic Hello, World in various locales
|
|||
- [x] Select the locale by id
|
||||
- [x] Use with CLI
|
||||
- [x] Basic HTTP server
|
||||
- [x] HTML frontend
|
||||
- [ ] Rebuild using [Aleph.js](https://alephjs.org/docs)
|
||||
- [ ] Deployment
|
||||
|
||||
## Installation
|
||||
|
||||
On macOS use HomeBrew to install `deno` then update to latest version.
|
||||
On macOS use HomeBrew to install `deno` then update to the latest version.
|
||||
|
||||
```shell
|
||||
brew install deno
|
||||
|
|
@ -47,29 +52,34 @@ with the following content
|
|||
|
||||
## 🚀 Run
|
||||
|
||||
See [Makefile](Makefile) for available scripts.
|
||||
The application can run either via CLI or a basic HTTP server.
|
||||
See [Makefile](Makefile) for available scripts. The application can run either
|
||||
via CLI or a basic HTTP server.
|
||||
|
||||
## 🧪 Tests
|
||||
|
||||
```shell
|
||||
make tests
|
||||
make tests
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
|
||||
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of
|
||||
conduct, and the process for submitting pull requests to us.
|
||||
|
||||
## Versioning
|
||||
|
||||
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/rjNemo/deno_hello/tags).
|
||||
We use [SemVer](http://semver.org/) for versioning. For the versions available,
|
||||
see the [tags on this repository](https://github.com/rjNemo/deno_hello/tags).
|
||||
|
||||
## Authors
|
||||
|
||||
- **Ruidy** - _Initial work_ - [Ruidy](https://github.com/rjNemo)
|
||||
|
||||
See also the list of [contributors](https://github.com/rjNemo/deno_hello/contributors) who participated in this project.
|
||||
See also the list of
|
||||
[contributors](https://github.com/rjNemo/deno_hello/contributors) who
|
||||
participated in this project.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
|
||||
This project is licensed under the MIT License - see the
|
||||
[LICENSE.md](LICENSE.md) file for details
|
||||
|
|
|
|||
11
deps.ts
11
deps.ts
|
|
@ -1,11 +0,0 @@
|
|||
export {
|
||||
assert,
|
||||
assertEquals,
|
||||
assertStrictEquals,
|
||||
assertThrows,
|
||||
} from "https://deno.land/std@0.87.0/testing/asserts.ts";
|
||||
export { readLines } from "https://deno.land/std@0.87.0/io/bufio.ts";
|
||||
export {
|
||||
listenAndServe,
|
||||
ServerRequest,
|
||||
} from "https://deno.land/std@0.87.0/http/server.ts";
|
||||
32
server.ts
32
server.ts
|
|
@ -1,32 +0,0 @@
|
|||
import { listenAndServe, ServerRequest } from "./deps.ts";
|
||||
import { ID, sayHello, sayRandomHello } from "./src/index.ts";
|
||||
|
||||
const port = 8000;
|
||||
|
||||
const parseURL = (url: string) => {
|
||||
const parts = url.slice(1).split("/");
|
||||
return parts[0];
|
||||
};
|
||||
|
||||
const serve = async (port: number) => {
|
||||
console.log(`Server listening on http://localhost:${port}/`);
|
||||
|
||||
await listenAndServe({ port }, (req: ServerRequest) => {
|
||||
console.log(`Request on address '${req.url}'`);
|
||||
|
||||
if (parseURL(req.url) === "") {
|
||||
return req.respond({ body: JSON.stringify(sayRandomHello()) });
|
||||
}
|
||||
|
||||
try {
|
||||
const value = parseInt(parseURL(req.url), 10);
|
||||
const id = new ID(value);
|
||||
return req.respond({ body: JSON.stringify(sayHello(id)) });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return req.respond({ body: error.message });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
await serve(port);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { readLines } from "./deps.ts";
|
||||
import { ID, sayHello, sayRandomHello, ValidationError } from "./src/index.ts";
|
||||
import { ID, sayHello, sayRandomHello, ValidationError } from "./mod.ts";
|
||||
|
||||
const start = async () => {
|
||||
console.log("Hello, World! (International version)\n");
|
||||
13
src/deps.ts
Normal file
13
src/deps.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
export {
|
||||
assert,
|
||||
assertEquals,
|
||||
assertStrictEquals,
|
||||
assertThrows,
|
||||
} from "https://deno.land/std@0.87.0/testing/asserts.ts";
|
||||
export { readLines } from "https://deno.land/std@0.87.0/io/bufio.ts";
|
||||
export { Application, Router } from "https://deno.land/x/oak/mod.ts";
|
||||
export type {
|
||||
RouteParams,
|
||||
RouterContext,
|
||||
} from "https://deno.land/x/oak/mod.ts";
|
||||
export { Random } from "https://deno.land/x/random/Random.js";
|
||||
9
src/main.ts
Normal file
9
src/main.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { router } from "./routes.ts";
|
||||
import { getApplication } from "./server.ts";
|
||||
|
||||
const port = 8000;
|
||||
|
||||
const app = getApplication({ port, router });
|
||||
|
||||
await app.listen({ port });
|
||||
console.log(`Finished`);
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { assertEquals } from "../../deps.ts";
|
||||
import { assertEquals } from "../deps.ts";
|
||||
import { getLocaleById, Locale } from "./locales.ts";
|
||||
|
||||
Deno.test("Get locale by id", () => {
|
||||
|
|
|
|||
24
src/routes.ts
Normal file
24
src/routes.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { Router, RouterContext } from "./deps.ts";
|
||||
import { ID, sayHello, sayRandomHello } from "./mod.ts";
|
||||
import { htmlBody } from "./view.ts";
|
||||
|
||||
export const router = new Router();
|
||||
|
||||
router.get("/", (ctx: RouterContext) => {
|
||||
ctx.response.body = htmlBody(sayRandomHello());
|
||||
});
|
||||
|
||||
router.get<
|
||||
Record<string, string | undefined>
|
||||
>("/:id", (ctx: RouterContext) => {
|
||||
try {
|
||||
const value = ctx.params.id;
|
||||
if (value && value !== "favicon.ico") {
|
||||
const id = new ID(parseInt(value, 10));
|
||||
ctx.response.body = htmlBody(sayHello(id));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
ctx.response.body = error.message;
|
||||
}
|
||||
});
|
||||
15
src/server.ts
Normal file
15
src/server.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { Application, Router } from "./deps.ts";
|
||||
|
||||
type AppOpts = { port: number; router: Router };
|
||||
|
||||
export const getApplication = ({ port, router }: AppOpts): Application => {
|
||||
const app = new Application();
|
||||
|
||||
app.use(router.routes());
|
||||
|
||||
app.addEventListener(
|
||||
"listen",
|
||||
() => console.log(`Server listening on http://localhost:${port}/`),
|
||||
);
|
||||
return app;
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { assertThrows } from "../../deps.ts";
|
||||
import { assert, assertThrows, Random } from "../deps.ts";
|
||||
import { ValidationError } from "../errors/exceptions.ts";
|
||||
import { ID } from "./id.ts";
|
||||
|
||||
|
|
@ -9,3 +9,9 @@ Deno.test("ID validation fails for non strictly positive values", () => {
|
|||
Deno.test("Hello fails for too large values", () => {
|
||||
assertThrows(() => new ID(666), ValidationError, `Invalid index: 666`);
|
||||
});
|
||||
|
||||
Deno.test("ID is valid", () => {
|
||||
const value = new Random().int(1, 77);
|
||||
const id = new ID(value);
|
||||
assert(id);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { assertEquals, assertStrictEquals } from "../../deps.ts";
|
||||
import { assertEquals, assertStrictEquals } from "../deps.ts";
|
||||
import { ID } from "../types/id.ts";
|
||||
import { HelloResponse, sayHello, sayRandomHello } from "./hello.ts";
|
||||
|
||||
|
|
|
|||
54
src/view.ts
Normal file
54
src/view.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { Locale } from "./repositories/locales.ts";
|
||||
|
||||
export const htmlBody = ({ locale: language, message: hello }: Locale) =>
|
||||
`<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<style>
|
||||
html,body {
|
||||
height: 100%;
|
||||
}
|
||||
body {
|
||||
max-width: 650px;
|
||||
margin: 40px auto;
|
||||
padding: 0 10px;
|
||||
font: 18px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
||||
color: #444;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
h1, h2, h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
body {
|
||||
color: white;
|
||||
background: #444;
|
||||
}
|
||||
|
||||
a:link {
|
||||
color: #5bf;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #ccf;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, maximum-scale=5.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<meta name="description" content="Simple client for Hello deno back end">
|
||||
<title>Hello client</title>
|
||||
</head>
|
||||
<body>
|
||||
<article>
|
||||
<h1>${hello}</h1>
|
||||
<p>Language: ${language}</p>
|
||||
</article>
|
||||
</body>
|
||||
</html>`;
|
||||
Loading…
Reference in a new issue