replace bun with pnpm and added dockerfile for web

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-11-02 11:29:28 +01:00
parent 4dde07704a
commit 9b329ef2f2
15 changed files with 5598 additions and 50 deletions

View File

@@ -1,3 +1,10 @@
**/.env
**/node_modules
**/dist
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
.git

47
apps/web/Dockerfile Normal file
View File

@@ -0,0 +1,47 @@
FROM node:20-slim AS base
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
ARG NEXTAUTH_SECRET
ENV NEXTAUTH_SECRET=$NEXTAUTH_SECRET
ARG NEXTAUTH_URL
ENV NEXTAUTH_URL=$NEXTAUTH_URL
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
ARG NODE_VERSION=18
RUN apt update \
&& apt install -y curl \
&& curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
&& bash n $NODE_VERSION \
&& rm n \
&& npm install -g n
FROM base AS build
COPY . /app
WORKDIR /app/apps/web
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --ignore-scripts
RUN pnpm dlx prisma generate
RUN pnpm run build
FROM base AS prod
COPY . /app
WORKDIR /app
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --prod --ignore-scripts
FROM base AS runner
COPY --from=build /app/package.json /app/package.json
COPY --from=prod /app/node_modules /app/node_modules
COPY --from=build /app/apps/web /app/apps/web
COPY --from=prod /app/apps/web/node_modules /app/apps/web/node_modules
WORKDIR /app/apps/web
RUN pnpm dlx prisma generate
EXPOSE 3000
CMD [ "pnpm", "start" ]

View File

@@ -1,5 +1,5 @@
{
"name": "web",
"name": "@mixan/web",
"version": "0.1.0",
"private": true,
"scripts": {
@@ -41,7 +41,7 @@
"cmdk": "^0.2.0",
"lucide-react": "^0.286.0",
"mitt": "^3.0.1",
"next": "^13.5.4",
"next": "13.4",
"next-auth": "^4.23.0",
"ramda": "^0.29.1",
"random-animal-name": "^0.1.1",
@@ -81,6 +81,5 @@
},
"ct3aMetadata": {
"initVersion": "7.21.0"
},
"packageManager": "npm@9.8.1"
}
}

View File

@@ -1,30 +1,27 @@
import { validateSdkRequest } from '@/server/auth'
import { db } from '@/server/db'
import { createError, handleError } from '@/server/exceptions'
import type { NextApiRequest, NextApiResponse } from 'next'
import randomAnimalName from 'random-animal-name'
import { validateSdkRequest } from "@/server/auth";
import { db } from "@/server/db";
import { createError, handleError } from "@/server/exceptions";
import type { NextApiRequest, NextApiResponse } from "next";
import randomAnimalName from "random-animal-name";
interface Request extends NextApiRequest {
body: {
id: string
properties?: Record<string, any>
}
id?: string;
properties?: Record<string, any>;
};
}
export default async function handler(
req: Request,
res: NextApiResponse
) {
if(req.method !== 'POST') {
return handleError(res, createError(405, 'Method not allowed'))
export default async function handler(req: Request, res: NextApiResponse) {
if (req.method !== "POST") {
return handleError(res, createError(405, "Method not allowed"));
}
try {
// Check client id & secret
const projectId = await validateSdkRequest(req)
const projectId = await validateSdkRequest(req);
const { id, properties } = req.body
await db.profile.create({
const { id, properties } = req.body ?? {};
const profile = await db.profile.create({
data: {
id,
external_id: null,
@@ -37,10 +34,10 @@ export default async function handler(
},
project_id: projectId,
},
})
});
res.status(200).end()
res.status(200).json({ id: profile.id });
} catch (error) {
handleError(res, error)
handleError(res, error);
}
}
}

BIN
bun.lockb

Binary file not shown.

View File

@@ -1,17 +1,16 @@
{
"name": "@mixan/root",
"version": "1.0.0",
"workspaces": ["apps/*", "packages/*"],
"keywords": [],
"author": "",
"packageManager": "pnpm@8.7.6",
"license": "ISC",
"module": "index.ts",
"type": "module",
"scripts": {
"dev": "cd apps/web && bun dev"
"dev": "pnpm -r dev"
},
"devDependencies": {
"bun-types": "latest",
"semver": "^7.5.4"
},
"peerDependencies": {

View File

@@ -34,7 +34,7 @@ class Fetcher {
post<Response extends unknown>(
path: string,
data: Record<string, any> = {},
options: FetchRequestInit = {}
options: RequestInit = {}
): Promise<Response | null> {
const url = `${this.url}${path}`
this.logger(`Mixan request: ${url}`, JSON.stringify(data, null, 2))
@@ -49,9 +49,7 @@ class Fetcher {
...options,
})
.then(async (res) => {
const response = await res.json<
MixanErrorResponse | Response
>()
const response = await res.json() as (MixanErrorResponse | Response)
if(!response) {
return null
@@ -78,7 +76,7 @@ class Fetcher {
class Batcher<T extends any> {
queue: T[] = []
timer?: Timer
timer?: NodeJS.Timeout
callback: (queue: T[]) => void
maxBatchSize: number
batchInterval: number

View File

@@ -8,7 +8,6 @@
},
"devDependencies": {
"@types/uuid": "^9.0.5",
"bun-types": "latest",
"tsup": "^7.2.0",
"typescript": "^5.0.0"
}

View File

@@ -17,9 +17,5 @@
"outDir": "dist",
"allowImportingTsExtensions": false,
"noEmit": false,
"types": [
"bun-types" // add Bun global
],
}
}

View File

@@ -3,13 +3,11 @@
To install dependencies:
```bash
bun install
pnpm install
```
To run:
```bash
bun run index.ts
pnpm run index.ts
```
This project was created using `bun init` in bun v1.0.4. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

View File

@@ -4,7 +4,6 @@
"type": "module",
"module": "index.ts",
"devDependencies": {
"bun-types": "latest",
"tsup": "^7.2.0",
"typescript": "^5.0.0"
}

View File

@@ -14,9 +14,6 @@
"jsx": "react-jsx",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"types": [
"bun-types" // add Bun global
]
"allowJs": true
}
}

5509
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

3
pnpm-workspace.yaml Normal file
View File

@@ -0,0 +1,3 @@
packages:
- 'apps/*'
- 'packages/*'

View File

@@ -47,10 +47,10 @@ function main() {
})
try {
execSync('bunx tsup', {
execSync('pnpm dlx tsup', {
cwd: './packages/sdk',
})
execSync('bunx tsup', {
execSync('pnpm dlx tsup', {
cwd: './packages/types',
})
} catch(error) {