Skip to content

Commit

Permalink
chore: Move the Foxify demo to examples directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalanamini committed Nov 13, 2022
1 parent 6c2f50e commit dc985da
Show file tree
Hide file tree
Showing 67 changed files with 258 additions and 203 deletions.
3 changes: 2 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@foxify/benchmark",
"foxify-benchmarks",
"fresh-benchmarks",
"router-benchmarks"
"router-benchmarks",
"foxify-example"
]
}
8 changes: 8 additions & 0 deletions .changeset/good-rules-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"foxify": patch
"@foxify/http": patch
"@foxify/inject": patch
"@foxify/router": patch
---

Fix module imports
2 changes: 0 additions & 2 deletions benchmarks/benchmark/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true,
"rootDir": ".",
"baseUrl": ".",
"noEmit": true
},
"files": [
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/foxify/servers/foxify-with-middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import hsts from "hsts";
import ienoopen from "ienoopen";
import xXssProtection from "x-xss-protection";

// eslint-disable-next-line new-cap
const app = (new Foxify.default);
const app = (new Foxify);

app.disable("x-powered-by");

Expand Down
3 changes: 1 addition & 2 deletions benchmarks/foxify/servers/foxify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import { SchemaOptionsI } from "@foxify/router";
import Foxify from "foxify";

// eslint-disable-next-line new-cap
const app = (new Foxify.default);
const app = (new Foxify);

app.disable("x-powered-by");

Expand Down
2 changes: 0 additions & 2 deletions benchmarks/foxify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true,
"rootDir": ".",
"baseUrl": ".",
"noEmit": true
}
}
4 changes: 1 addition & 3 deletions benchmarks/fresh/suites/etag-several.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import foxify from "@foxify/fresh";
import foxifyFresh from "@foxify/fresh";
import fresh from "fresh";

const foxifyFresh = foxify.default;

export default [
[
"@foxify/fresh",
Expand Down
4 changes: 1 addition & 3 deletions benchmarks/fresh/suites/etag-single.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import foxify from "@foxify/fresh";
import foxifyFresh from "@foxify/fresh";
import fresh from "fresh";

const foxifyFresh = foxify.default;

export default [
[
"@foxify/fresh",
Expand Down
4 changes: 1 addition & 3 deletions benchmarks/fresh/suites/etag-star.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import foxify from "@foxify/fresh";
import foxifyFresh from "@foxify/fresh";
import fresh from "fresh";

const foxifyFresh = foxify.default;

export default [
[
"@foxify/fresh",
Expand Down
4 changes: 1 addition & 3 deletions benchmarks/fresh/suites/modified.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import foxify from "@foxify/fresh";
import foxifyFresh from "@foxify/fresh";
import fresh from "fresh";

const foxifyFresh = foxify.default;

export default [
[
"@foxify/fresh",
Expand Down
4 changes: 1 addition & 3 deletions benchmarks/fresh/suites/not-modified.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import foxify from "@foxify/fresh";
import foxifyFresh from "@foxify/fresh";
import fresh from "fresh";

const foxifyFresh = foxify.default;

export default [
[
"@foxify/fresh",
Expand Down
1 change: 0 additions & 1 deletion benchmarks/fresh/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"baseUrl": ".",
"noEmit": true
}
}
4 changes: 1 addition & 3 deletions benchmarks/router/routers/foxify.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import foxify from "@foxify/router";
import Router from "@foxify/router";
import { routes, noop } from "./common.js";

const Router = foxify.default;

const router = (new Router);

routes.forEach((route) => {
Expand Down
1 change: 0 additions & 1 deletion benchmarks/router/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"baseUrl": ".",
"noEmit": true
}
}
3 changes: 3 additions & 0 deletions examples/foxify/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Foxify Example

> TODO
22 changes: 22 additions & 0 deletions examples/foxify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "foxify-example",
"version": "0.0.0",
"private": true,
"description": "Foxify Benchmarks",
"type": "module",
"scripts": {
"start": "ts-node-esm src/index.ts"
},
"dependencies": {
"@foxify/http": "workspace:^",
"@foxify/router": "workspace:^",
"foxify": "workspace:^",
"ejs": "^3.1.8",
"morgan": "^1.10.0"
},
"devDependencies": {
"@types/ejs": "^3.1.1",
"@types/morgan": "^1.9.3",
"@types/node": "^18.11.9"
}
}
File renamed without changes.
38 changes: 38 additions & 0 deletions examples/foxify/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import path from "node:path";
import url from "node:url";
import Foxify from "foxify";
import morgan from "morgan";
import routes from "./routes/index.js";

const ROOT_DIR = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "..");

const app = (new Foxify);

// Settings
app
.set("url", "localhost")
.set("port", 3000)
.set("workers", 1);

// Template engine support
app.engine(
"ejs",
path.join(ROOT_DIR, "views"),
// eslint-disable-next-line no-underscore-dangle,@typescript-eslint/no-explicit-any
(await import("ejs") as any).__express,
);

// Static serve support
app.use(Foxify.static(path.join(ROOT_DIR, "public")));

// Express middleware support
app.use(morgan("dev"));

// Routes
app.use(routes);

// Log the routes
console.info(app.prettyPrint());

// Start the app
app.start(() => console.info(`Foxify server running at http://${ app.setting("url") }:${ app.setting("port") } (worker: ${ process.pid })`));
48 changes: 48 additions & 0 deletions examples/foxify/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { STATUS, HttpError } from "@foxify/http";
import Router, { SchemaOptionsI } from "@foxify/router";

const router = (new Router);

router.get("/", (req, res) => {
res.render("index", {
logo : "https://avatars1.githubusercontent.com/u/36167886?s=200&v=4",
title: "Foxify",
});
});

router.get("/greet", (req, res) => {
res.json({
hello: "world",
});
});

const schema: SchemaOptionsI = {
response: {
200: {
type : "object",
properties: {
hello: {
type: "string",
},
},
},
},
};

router.get("/greet-fast", {
schema,
}, (req, res) => {
res.json({
hello: "world",
});
});

router.get("/404", () => {
throw new HttpError("This is a demo", STATUS.NOT_FOUND);
});

router.get("/error", async () => {
throw new Error("Oops!");
});

export default router;
7 changes: 7 additions & 0 deletions examples/foxify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"noEmit": true
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<title><%= title %></title>

<link rel="stylesheet" href="/src/style.css">
<link rel="stylesheet" href="/style.css">
</head>

<body>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% include header.ejs %>
<%- include('header') -%>

<div style="text-align: center;">
<img src="<%= logo %>" />
Expand All @@ -8,4 +8,4 @@
</a>
</div>

<% include footer.ejs %>
<%- include('footer') -%>
4 changes: 3 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ module.exports = {

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources
// with a single module
// moduleNameMapper: {},
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},

// An array of regexp pattern strings,
// matched against all module paths before considered 'visible' to the module loader
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"typescript": "^4.8.4"
},
"workspaces": [
"packages/*",
"benchmarks/*"
"benchmarks/*",
"examples/*",
"packages/*"
]
}
1 change: 1 addition & 0 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"build:pre": "ts-node-esm ../../scripts/pre-build.mts",
"build:post": "ts-node-esm ../../scripts/post-build.mts"
},
"type": "module",
"engines": {
"node": ">=16"
},
Expand Down
1 change: 0 additions & 1 deletion packages/foxify/.npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
tests/
coverage/
demo/
tsconfig*.json
*.tsbuildinfo
6 changes: 0 additions & 6 deletions packages/foxify/demo/.env.example

This file was deleted.

31 changes: 0 additions & 31 deletions packages/foxify/demo/index.js

This file was deleted.

Loading

0 comments on commit dc985da

Please sign in to comment.