Compare commits

..

No commits in common. "master" and "v0.1.0" have entirely different histories.

31 changed files with 215 additions and 214 deletions

3
.gitignore vendored
View file

@ -26,6 +26,3 @@ Icon
Network Trash Folder
Temporary Items
.apdisk
.coverage
.idea/

View file

@ -1,2 +0,0 @@
tasks:
- init: make

8
.idea/.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View file

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

6
.idea/deno.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DenoSettings">
<option name="useDeno" value="true" />
</component>
</project>

6
.idea/dictionaries Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectDictionaryState">
<dictionary name="ruidy" />
</component>
</project>

11
.idea/hello-server.iml Normal file
View file

@ -0,0 +1,11 @@
<?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>

View file

@ -0,0 +1,16 @@
<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>

View file

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View file

@ -0,0 +1,4 @@
<?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>

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?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>

7
.idea/prettier.xml Normal file
View file

@ -0,0 +1,7 @@
<?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>

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

25
.idea/watcherTasks.xml Normal file
View file

@ -0,0 +1,25 @@
<?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
View file

@ -1,19 +1,14 @@
{
"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
}
"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"
}
}

View file

@ -1,25 +1,20 @@
# 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
@ -28,9 +23,9 @@ with the project.
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
@ -60,11 +55,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
@ -81,9 +76,8 @@ 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
@ -91,8 +85,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/

View file

@ -2,19 +2,20 @@
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.

View file

@ -1,12 +1,8 @@
.PHONY: cli
cli:
deno run cli.ts
.PHONY: run
run:
deno run --watch --allow-net src/main.ts
lint:
deno lint --unstable
test: tests
deno run --allow-net server.ts
tests:
deno test --coverage=.coverage --unstable
deno coverage .coverage
.PHONY: cli run lint test tests
deno test --coverage --unstable

View file

@ -1,8 +1,6 @@
[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](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
@ -10,13 +8,10 @@ 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 the latest version.
On macOS use HomeBrew to install `deno` then update to latest version.
```shell
brew install deno
@ -52,34 +47,29 @@ 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

View file

@ -1,5 +1,5 @@
import { readLines } from "./deps.ts";
import { ID, sayHello, sayRandomHello, ValidationError } from "./mod.ts";
import { ID, sayHello, sayRandomHello, ValidationError } from "./src/index.ts";
const start = async () => {
console.log("Hello, World! (International version)\n");

11
deps.ts Normal file
View file

@ -0,0 +1,11 @@
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 Normal file
View file

@ -0,0 +1,32 @@
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);

View file

@ -1,13 +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 { 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";

View file

@ -1,9 +0,0 @@
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`);

View file

@ -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", () => {

View file

@ -1,24 +0,0 @@
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;
}
});

View file

@ -1,15 +0,0 @@
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;
};

View file

@ -1,4 +1,4 @@
import { assert, assertThrows, Random } from "../deps.ts";
import { assertThrows } from "../../deps.ts";
import { ValidationError } from "../errors/exceptions.ts";
import { ID } from "./id.ts";
@ -9,9 +9,3 @@ 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);
});

View file

@ -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";

View file

@ -1,54 +0,0 @@
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>`;