Skip to content

Commit

Permalink
feat: removed webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
MathurAditya724 committed Mar 21, 2024
1 parent a1c8eec commit f171abe
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 98 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ testem.log
.DS_Store
Thumbs.db

.nx/cache
.nx/cache
.vercel
34 changes: 34 additions & 0 deletions apps/sandbox/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"target": "es2022",
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true
},
"keepClassNames": true,
"externalHelpers": false,
"loose": true
},
"module": {
"type": "es6",
"strictMode": true,
"noInterop": false
},
"minify": true,
"sourceMaps": false,
"exclude": [
"vite.config.ts",
".*\\.spec.tsx?$",
".*\\.test.tsx?$",
"./src/vite-setup.ts$",
"./**/vite-setup.ts$",
".*.js$",
"./**/__tests__/**/*"
]
}
2 changes: 1 addition & 1 deletion apps/sandbox/src/Card.tsx → apps/sandbox/api/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const valueClass = css`
}
`;

export type Card = { label: string; value: string | number };
export type Card = { label: string; value?: string | number };

const Card: FC<Card> = ({ label, value }: Card) => {
return (
Expand Down
4 changes: 2 additions & 2 deletions apps/sandbox/src/Layout.tsx → apps/sandbox/api/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Style, css } from "hono/css";
import type { FC } from "hono/jsx";
import type { FC, PropsWithChildren } from "hono/jsx";

const globalClasses = css`
font-family: "Inter", sans-serif;
Expand Down Expand Up @@ -30,7 +30,7 @@ const mainClass = css`
}
`;

const Layout: FC = (props) => {
const Layout: FC<PropsWithChildren> = (props: PropsWithChildren) => {
return (
<html lang="en">
<head>
Expand Down
6 changes: 3 additions & 3 deletions apps/sandbox/src/Page.tsx → apps/sandbox/api/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { RateLimitInfo } from "hono-rate-limiter";
import { css } from "hono/css";
import type { FC } from "hono/jsx";
import Card from "./Card";
import Layout from "./Layout";
import Card from "./Card.js";
import Layout from "./Layout.js";

const checkOut = css`
font-family: monospace;
Expand Down Expand Up @@ -83,7 +83,7 @@ const Page: FC<Page> = ({ info: { limit, remaining, resetTime } }: Page) => {
},
{
label: "Reset",
value: resetTime.toUTCString(),
value: resetTime?.toUTCString(),
},
];

Expand Down
4 changes: 4 additions & 0 deletions apps/sandbox/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { handle } from "hono/vercel";
import { app } from "./main.js";

export default handle(app);
65 changes: 27 additions & 38 deletions apps/sandbox/src/main.tsx → apps/sandbox/api/main.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
import { serve } from "@hono/node-server";
import { kv } from "@vercel/kv";
import { Hono } from "hono";
import { type RateLimitInfo, rateLimiter } from "hono-rate-limiter";
import { logger } from "hono/logger";
import Page from "./Page";

// Init the app
const app = new Hono<{
Variables: {
rateLimit: RateLimitInfo;
};
}>();

// Adding the rate limitter
app.use(
logger(),
rateLimiter({
windowMs: 10_000,
limit: 10,
// store: new RedisStore({
// sendCommand: (...args: string[]) => kv.eval(...args),
// }),
handler: (_, next) => next(),
}),
);

// Routes
app.get("/", (c) => c.html(<Page info={c.get("rateLimit")} />));

// Serving the app
const port = Number(process.env.PORT) || 3000;
console.log(`Server is running on port ${port}`);

serve({
fetch: app.fetch,
port,
});
import { Hono } from "hono";
import { type RateLimitInfo, rateLimiter } from "hono-rate-limiter";
import { logger } from "hono/logger";
import Page from "./Page.js";

// Init the app
export const app = new Hono<{
Variables: {
rateLimit: RateLimitInfo;
};
}>();

// Adding the rate limitter
app.use(
logger(),
rateLimiter({
windowMs: 10_000,
limit: 10,
// store: new RedisStore({
// sendCommand: (...args: string[]) => kv.eval(...args),
// }),
handler: (_, next) => next(),
}),
);

// Routes
app.get("/", (c) => c.html(<Page info={c.get("rateLimit")} />));
6 changes: 6 additions & 0 deletions apps/sandbox/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "module",
"dependencies": {
"hono": "^4.1.3"
}
}
21 changes: 8 additions & 13 deletions apps/sandbox/project.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
{
"name": "sandbox",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/sandbox/src",
"sourceRoot": "apps/sandbox/api",
"projectType": "application",
"targets": {
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"build": {
"executor": "@nx/js:swc",
"outputs": ["{options.outputPath}"],
"options": {
"buildTarget": "sandbox:build"
},
"configurations": {
"development": {
"buildTarget": "sandbox:build:development"
},
"production": {
"buildTarget": "sandbox:build:production"
}
"outputPath": "dist/apps/sandbox",
"main": "apps/sandbox/api/index.ts",
"tsConfig": "apps/sandbox/tsconfig.json",
"assets": ["apps/sandbox/public/*"]
}
}
},
Expand Down
Binary file added apps/sandbox/public/favicon.ico
Binary file not shown.
12 changes: 0 additions & 12 deletions apps/sandbox/tsconfig.app.json

This file was deleted.

32 changes: 23 additions & 9 deletions apps/sandbox/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
}
],
"compilerOptions": {
"esModuleInterop": true
}
"module": "esnext",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"target": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx",
"outDir": "../../dist/out-tsc",
"declaration": true
},

"include": ["api/**/*.ts", "api/**/*.tsx"],
"exclude": [
"vite.config.ts",
"api/**/*.spec.ts",
"api/**/*.test.ts",
"./**/__tests__/*"
]
}
8 changes: 8 additions & 0 deletions apps/sandbox/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rewrites": [
{
"source": "/(.*)",
"destination": "/api"
}
]
}
19 changes: 0 additions & 19 deletions apps/sandbox/webpack.config.js

This file was deleted.

0 comments on commit f171abe

Please sign in to comment.