Skip to content

Commit 6480667

Browse files
authored
Split backend and dashboard (stack-auth#83)
1 parent 02c19ec commit 6480667

File tree

397 files changed

+5968
-479
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

397 files changed

+5968
-479
lines changed

.github/workflows/e2e-api-tests.yaml

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,31 @@ jobs:
3030
uses: pnpm/action-setup@v3
3131
with:
3232
version: 9.1.2
33-
34-
- name: Create .env.local file for stack-server
35-
run: |
36-
cat > packages/stack-server/.env.local <<EOF
37-
NEXT_PUBLIC_STACK_URL=http://localhost:8101
38-
NEXT_PUBLIC_STACK_PROJECT_ID=internal
39-
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=internal-project-client-api-key
40-
STACK_SECRET_SERVER_KEY=internal-project-server-api-key
41-
SERVER_SECRET=23-wuNpik0gIW4mruTz25rbIvhuuvZFrLOLtL7J4tyo
4233

43-
EMAIL_HOST=0.0.0.0
44-
EMAIL_PORT=2500
45-
EMAIL_USERNAME=some-username
46-
EMAIL_PASSWORD=some-password
47-
EMAIL_SENDER=noreply@example.com
48-
49-
DATABASE_CONNECTION_STRING=postgres://postgres:password@localhost:5432/stackframe
50-
DIRECT_DATABASE_CONNECTION_STRING=postgres://postgres:password@localhost:5432/stackframe
51-
EOF
52-
5334
- name: Install dependencies
5435
run: pnpm install --frozen-lockfile
5536

37+
- name: Create .env.local file for stack-backend
38+
run: cp apps/backend/.env.development apps/backend/.env.production.local
39+
40+
- name: Create .env.local file for stack-dashboard
41+
run: cp apps/dashboard/.env.development apps/dashboard/.env.production.local
42+
43+
- name: Build stack-backend
44+
run: pnpm build:backend
45+
46+
- name: Build stack-dashboard
47+
run: pnpm build:dashboard
48+
5649
- name: Start Docker Compose
5750
run: docker-compose -f dependencies.compose.yaml up -d
5851
- name: Initialize database
59-
run: pnpm run prisma:server -- migrate reset --force
60-
61-
- name: Build stack-server
62-
run: pnpm build:server
52+
run: pnpm run prisma -- migrate reset --force
6353

64-
- name: Start stack-server in background
65-
run: pnpm -C packages/stack-server start &
66-
- name: Wait for stack-server to start
54+
- name: Start stack-dashboard in background
55+
run: pnpm run start:dashboard &
56+
- name: Wait for stack-dashboard to start
6757
run: npx wait-on@7.2.0 http://localhost:8101
6858

6959
- name: Run tests
70-
run: pnpm -C apps/e2e test:ci
71-
env:
72-
SERVER_BASE_URL: http://localhost:8101
73-
INTERNAL_PROJECT_ID: internal
74-
INTERNAL_PROJECT_CLIENT_KEY: internal-project-client-api-key
60+
run: pnpm test

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,26 @@ pnpm run build
9898
pnpm run codegen
9999

100100
# Push the most recent Prisma schema to the database
101-
pnpm run prisma:server db push
101+
pnpm run prisma db push
102102

103103
# Start the dev server
104104
pnpm run dev
105105
```
106106

107-
You can now open the dashboard at [http://localhost:8101](http://localhost:8101), demo on port 8103, and docs on port 8104.
107+
You can now open the dashboard at [http://localhost:8101](http://localhost:8101), API on port 8102, demo on port 8103, and docs on port 8104. You can also run the tests with `pnpm run test:watch`.
108108

109109
Your IDE may show an error on all `@stackframe/XYZ` imports. To fix this, simply restart the TypeScript language server; for example, in VSCode you can open the command palette (Ctrl+Shift+P) and run `Developer: Reload Window` or `TypeScript: Restart TS server`.
110110

111111
You can also open Prisma Studio to see the database interface and edit data directly:
112112

113113
```sh
114-
pnpm run prisma:server studio
114+
pnpm run prisma studio
115115
```
116116

117117
### Database migrations
118118

119119
If you make changes to the Prisma schema, you need to run the following command to create a migration:
120120

121121
```sh
122-
pnpm run prisma:server migrate dev
122+
pnpm run prisma migrate dev
123123
```

apps/backend/.env

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Basic
2+
SERVER_SECRET=# enter a secret key generated by `pnpm generate-keys` here. This is used to sign the JWT tokens.
3+
4+
# OAuth shared keys
5+
# Can be omitted if shared OAuth keys are not needed
6+
GITHUB_CLIENT_ID=# client
7+
GITHUB_CLIENT_SECRET=# client secret
8+
GOOGLE_CLIENT_ID=# client id
9+
GOOGLE_CLIENT_SECRET=# client secret
10+
FACEBOOK_CLIENT_ID=# client id
11+
FACEBOOK_CLIENT_SECRET=# client secret
12+
MICROSOFT_CLIENT_ID=# client id
13+
MICROSOFT_CLIENT_SECRET=# client secret
14+
SPOTIFY_CLIENT_ID=# client id
15+
SPOTIFY_CLIENT_SECRET=# client secret
16+
17+
# Email
18+
# For local development, you can spin up a local SMTP server like inbucket
19+
EMAIL_HOST=# for local inbucket: 0.0.0.0
20+
EMAIL_PORT=# for local inbucket: 2500
21+
EMAIL_USERNAME=# for local inbucket: test
22+
EMAIL_PASSWORD=# for local inbucket: none
23+
EMAIL_SENDER=# for local inbucket: noreply@test.com
24+
25+
# Database
26+
# For local development: `docker run -it --rm -e POSTGRES_PASSWORD=password -p "5432:5432" postgres`
27+
DATABASE_CONNECTION_STRING=# enter your connection string here. For local development: `postgres://postgres:password@localhost:5432/stack`
28+
DIRECT_DATABASE_CONNECTION_STRING=# enter your direct (unpooled or session mode) database connection string here. For local development: same as above
29+
30+
# Misc, optional
31+
STACK_ACCESS_TOKEN_EXPIRATION_TIME=# enter the expiration time for the access token here. Optional, don't specify it for default value

apps/backend/.env.development

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SERVER_SECRET=23-wuNpik0gIW4mruTz25rbIvhuuvZFrLOLtL7J4tyo
2+
3+
DATABASE_CONNECTION_STRING=postgres://postgres:password@localhost:5432/stackframe
4+
DIRECT_DATABASE_CONNECTION_STRING=postgres://postgres:password@localhost:5432/stackframe
5+
6+
NEXT_PUBLIC_DOC_URL=http://localhost:8104
7+
8+
EMAIL_HOST=0.0.0.0
9+
EMAIL_PORT=2500
10+
EMAIL_SECURE=false
11+
EMAIL_USERNAME=does not matter, ignored by Inbucket
12+
EMAIL_PASSWORD=does not matter, ignored by Inbucket
13+
EMAIL_SENDER=noreply@example.com

apps/backend/.eslintrc.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
extends: ["../../eslint-configs/defaults.js", "../../eslint-configs/next.js"],
3+
ignorePatterns: ["/*", "!/src", "!/prisma"],
4+
rules: {},
5+
};

apps/backend/next.config.mjs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { withSentryConfig } from "@sentry/nextjs";
2+
import createBundleAnalyzer from "@next/bundle-analyzer";
3+
4+
const withBundleAnalyzer = createBundleAnalyzer({
5+
enabled: !!process.env.ANALYZE_BUNDLE,
6+
});
7+
8+
const withConfiguredSentryConfig = (nextConfig) =>
9+
withSentryConfig(
10+
nextConfig,
11+
{
12+
// For all available options, see:
13+
// https://github.com/getsentry/sentry-webpack-plugin#options
14+
15+
// Suppresses source map uploading logs during build
16+
silent: true,
17+
org: "stackframe-pw",
18+
project: "stack-api",
19+
},
20+
{
21+
// For all available options, see:
22+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
23+
24+
// Upload a larger set of source maps for prettier stack traces (increases build time)
25+
widenClientFileUpload: true,
26+
27+
// Transpiles SDK to be compatible with IE11 (increases bundle size)
28+
transpileClientSDK: true,
29+
30+
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
31+
// This can increase your server load as well as your hosting bill.
32+
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
33+
// side errors will fail.
34+
tunnelRoute: "/monitoring",
35+
36+
// Hides source maps from generated client bundles
37+
hideSourceMaps: true,
38+
39+
// Automatically tree-shake Sentry logger statements to reduce bundle size
40+
disableLogger: true,
41+
42+
// Enables automatic instrumentation of Vercel Cron Monitors.
43+
// See the following for more information:
44+
// https://docs.sentry.io/product/crons/
45+
// https://vercel.com/docs/cron-jobs
46+
automaticVercelMonitors: true,
47+
}
48+
);
49+
50+
/** @type {import('next').NextConfig} */
51+
const nextConfig = {
52+
// we're open-source, so we can provide source maps
53+
productionBrowserSourceMaps: true,
54+
poweredByHeader: false,
55+
56+
async headers() {
57+
return [
58+
{
59+
source: "/(.*)",
60+
headers: [
61+
{
62+
key: "Cross-Origin-Opener-Policy",
63+
value: "same-origin",
64+
},
65+
{
66+
key: "Permissions-Policy",
67+
value: "",
68+
},
69+
{
70+
key: "Referrer-Policy",
71+
value: "strict-origin-when-cross-origin",
72+
},
73+
{
74+
key: "X-Content-Type-Options",
75+
value: "nosniff",
76+
},
77+
{
78+
key: "X-Frame-Options",
79+
value: "SAMEORIGIN",
80+
},
81+
{
82+
key: "Content-Security-Policy",
83+
value: "",
84+
},
85+
],
86+
},
87+
];
88+
},
89+
};
90+
91+
export default withConfiguredSentryConfig(
92+
withBundleAnalyzer(
93+
nextConfig
94+
)
95+
);

apps/backend/package.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "@stackframe/stack-backend",
3+
"version": "2.4.26",
4+
"private": true,
5+
"scripts": {
6+
"clean": "rimraf .next && rimraf node_modules",
7+
"typecheck": "tsc --noEmit",
8+
"with-env": "dotenv -c development --",
9+
"with-env:prod": "dotenv -c --",
10+
"dev": "concurrently \"next dev --port 8102\" \"npm run watch-docs\"",
11+
"build": "npm run codegen && next build",
12+
"analyze-bundle": "ANALYZE_BUNDLE=1 npm run build",
13+
"start": "next start --port 8102",
14+
"codegen": "npm run prisma -- generate && npm run generate-docs",
15+
"psql": "npm run with-env -- bash -c 'psql $DATABASE_CONNECTION_STRING'",
16+
"prisma": "npm run with-env -- prisma",
17+
"lint": "next lint",
18+
"watch-docs": "npm run with-env -- chokidar --silent '../../**/*' -i '../../docs/**' -i '../../**/node_modules/**' -i '../../**/.next/**' -i '../../**/dist/**' -c 'tsx scripts/generate-docs.ts'",
19+
"generate-docs": "npm run with-env -- tsx scripts/generate-docs.ts",
20+
"generate-keys": "npm run with-env -- tsx scripts/generate-keys.ts"
21+
},
22+
"prisma": {
23+
"seed": "npm run with-env -- tsx prisma/seed.ts"
24+
},
25+
"dependencies": {
26+
"@hookform/resolvers": "^3.3.4",
27+
"@next/bundle-analyzer": "^14.0.3",
28+
"@node-oauth/oauth2-server": "^5.1.0",
29+
"@prisma/client": "^5.9.1",
30+
"@react-email/components": "^0.0.14",
31+
"@react-email/render": "^0.0.12",
32+
"@react-email/tailwind": "^0.0.14",
33+
"@sentry/nextjs": "^7.105.0",
34+
"@stackframe/stack-shared": "workspace:*",
35+
"@vercel/analytics": "^1.2.2",
36+
"bcrypt": "^5.1.1",
37+
"date-fns": "^3.6.0",
38+
"dotenv-cli": "^7.3.0",
39+
"handlebars": "^4.7.8",
40+
"jose": "^5.2.2",
41+
"lodash": "^4.17.21",
42+
"next": "^14.1",
43+
"nodemailer": "^6.9.10",
44+
"openid-client": "^5.6.4",
45+
"pg": "^8.11.3",
46+
"posthog-js": "^1.138.1",
47+
"prettier": "^3.2.5",
48+
"react": "^18.2",
49+
"react-email": "2.1.0",
50+
"server-only": "^0.0.1",
51+
"sharp": "^0.32.6",
52+
"yaml": "^2.4.5",
53+
"yup": "^1.4.0"
54+
},
55+
"devDependencies": {
56+
"@types/bcrypt": "^5.0.2",
57+
"@types/lodash": "^4.17.4",
58+
"@types/node": "^20.8.10",
59+
"@types/nodemailer": "^6.4.14",
60+
"@types/react": "^18.2.66",
61+
"prisma": "^5.9.1",
62+
"rimraf": "^5.0.5",
63+
"tsx": "^4.7.2",
64+
"glob": "^10.4.1"
65+
}
66+
}

packages/stack-server/prisma/migrations/20240306152532_initial_migration/migration.sql renamed to apps/backend/prisma/migrations/20240306152532_initial_migration/migration.sql

File renamed without changes.

0 commit comments

Comments
 (0)