Skip to content

Commit

Permalink
feat: switch to mono
Browse files Browse the repository at this point in the history
  • Loading branch information
williamluke4 committed Jul 30, 2024
1 parent 7e6b4a5 commit 468e736
Show file tree
Hide file tree
Showing 404 changed files with 10,607 additions and 5,801 deletions.
59 changes: 56 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
.next
/out/

# production
Expand Down Expand Up @@ -43,4 +43,57 @@ export.sh


# Dev snapshots
dev/*.bz2
dev/*.bz2

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules
.pnp
.pnp.js

# testing
coverage

# next.js
.next/
out/
next-env.d.ts

# nitro
.nitro/
.output/

# expo
.expo/
expo-env.d.ts
apps/expo/.gitignore
apps/expo/ios
apps/expo/android

# production
build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
dist/

# turbo
.turbo
52 changes: 52 additions & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "examples-fastify-server",
"private": true,
"type": "module",
"scripts": {
"build": "esbuild src/server/index.ts src/client/index.ts --bundle --packages=external --platform=node --format=esm --outdir=dist --sourcemap",
"dev": "dotenv -e ../../.env -- tsx watch src/server",
"lint": "eslint --cache --ext \".js,.ts,.tsx\" src",
"type-check": "tsc",
"start:server": "node dist/server/index.js",
"start": "run-p start:* --print-label",
"test-dev": "start-server-and-test 'tsx src/server' http-get://localhost:2022 'tsx src/client'",
"test-start": "start-server-and-test 'node dist/server' http-get://localhost:2022 'node dist/client'"
},
"dependencies": {
"@grassroots/api": "workspace:*",
"@grassroots/auth": "workspace:*",
"@grassroots/contracts": "workspace:*",
"@grassroots/db": "workspace:*",
"@grassroots/shared": "workspace:*",
"@grassroots/validators": "workspace:*",
"@trpc/client": "11.0.0-rc.441",
"@trpc/server": "11.0.0-rc.441",
"cors": "^2.8.5",
"express": "^4.17.1",
"iron-session": "^8.0.1",
"kysely": "^0.27.3",
"superjson": "2.2.1",
"tslib": "^2.5.0",
"viem": "catalog:",
"ws": "^8.0.0",
"zod": "catalog:"
},
"devDependencies": {
"@grassroots/tsconfig": "workspace:*",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.17",
"@types/node": "catalog:",
"@types/ws": "^8.2.0",
"dotenv-cli": "^7.4.2",
"esbuild": "^0.17.10",
"eslint": "^8.57.0",
"npm-run-all": "^4.1.5",
"start-server-and-test": "^1.12.0",
"tsx": "^4.0.0",
"typescript": "^5.4.5",
"wait-port": "^1.0.1"
},
"publishConfig": {
"access": "restricted"
}
}
7 changes: 7 additions & 0 deletions apps/server/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { ServerOptions } from './server/server';

export const serverConfig: ServerOptions = {
dev: false,
port: 2022,
prefix: '/trpc',
};
6 changes: 6 additions & 0 deletions apps/server/src/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { serverConfig } from '../config';
import { createServer } from './server';

const server = createServer(serverConfig);

void server.start();
20 changes: 20 additions & 0 deletions apps/server/src/server/iron-session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { NextFunction, Request, Response } from "express";
import type { IronSession, SessionOptions } from "iron-session";
import { Session } from "@grassroots/auth";
import { getIronSession } from "iron-session";

declare module "http" {
interface IncomingMessage {
session: IronSession<Session> | null;
}
}

// middleware
export function ironSession(
sessionOptions: SessionOptions,
): (req: Request, res: Response, next: NextFunction) => Promise<void> {
return async function ironSessionMiddleware(req, res, next) {
req.session = await getIronSession(req, res, sessionOptions);
next();
};
}
61 changes: 61 additions & 0 deletions apps/server/src/server/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Server } from "http";
import { appRouter, createContext } from "@grassroots/api";
import { sessionOptions } from "@grassroots/auth";
import * as trpcExpress from "@trpc/server/adapters/express";
import cors from "cors";
import express from "express";

import { ironSession } from "./iron-session";

export interface ServerOptions {
dev?: boolean;
port?: number;
prefix?: string;
}
// express implementation

let server: Server;

export function createServer(opts: ServerOptions) {
const dev = opts.dev ?? true;
const port = opts.port ?? 3000;
const prefix = opts.prefix ?? "/trpc";
const app = express();

app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
}),
);
app.use(ironSession(sessionOptions));
app.use(
"/trpc",
trpcExpress.createExpressMiddleware({
router: appRouter,
createContext,
}),
);

app.get("/", async () => {
return { hello: "wait-on 💨" };
});

const start = async () => {
try {
server = app.listen({ port });
console.log("listening on port", port);
} catch (err) {
console.error(err);
process.exit(1);
}
};
const stop = async () => {
if (!server) {
console.error("Server not running");
process.exit(1);
}
server.close();
};
return { server, start, stop };
}
18 changes: 18 additions & 0 deletions apps/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "@grassroots/tsconfig/base.json",
"compilerOptions": {
"lib": ["es2022"],
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"]
},
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json",
"module": "esnext"
},
"include": [
".",
"../../packages/api/src/context.ts",
"../../packages/auth/src/auth.ts"
],
"exclude": ["node_modules"]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 12 additions & 2 deletions next.config.mjs → apps/website/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
* for Docker builds.
*/
import withBundleAnalyzer from "@next/bundle-analyzer";
import createJiti from "jiti";

const jiti = createJiti(new URL(import.meta.url).pathname);

jiti("./src/env");

import withBundleAnalyzer from "@next/bundle-analyzer";

const bundleAnalyzer = withBundleAnalyzer({
enabled: process.env.ANALYZE === "true",
});
Expand All @@ -17,8 +17,18 @@ const config = {
reactStrictMode: true,
webpack: (config) => {
config.resolve.fallback = { fs: false, net: false, tls: false };
config.module.rules.push({
test: /\.node/,
use: 'node-loader'
})
return config;
},
transpilePackages: [
"@grassroots/paper-wallet",
"@grassroots/shared",
"@grassroots/contracts",
"@grassroots/auth",
],
async redirects() {
return [
// Basic redirect
Expand Down
Loading

0 comments on commit 468e736

Please sign in to comment.