Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
📝 Add Blitz demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
Errorname committed Aug 16, 2020
1 parent c65dab2 commit 012c835
Show file tree
Hide file tree
Showing 52 changed files with 14,030 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/examples/apollo/prisma/.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ DATABASE_URL=file:dev.db

# The following env variables are used by prisma-multi-tenant

MANAGEMENT_URL=file:management.db
MANAGEMENT_URL=file:prisma/management.db
Empty file.
2 changes: 1 addition & 1 deletion docs/examples/basic-ts/prisma/.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ DATABASE_URL=file:dev.db

# The following env variables are used by prisma-multi-tenant

MANAGEMENT_URL=file:management.db
MANAGEMENT_URL=file:prisma/management.db
4 changes: 4 additions & 0 deletions docs/examples/blitz/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ["next/babel"],
plugins: [],
}
9 changes: 9 additions & 0 deletions docs/examples/blitz/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# THIS FILE SHOULD NOT BE CHECKED INTO YOUR VERSION CONTROL SYSTEM

# You can use this file to specify secrets like your database connection information
# if you move to a more sophisticated database than sqlite. For example, for postgres:
DATABASE_URL=file:./db.sqlite

# The following env variable is used by prisma-multi-tenant

MANAGEMENT_URL=file:db/management.db
10 changes: 10 additions & 0 deletions docs/examples/blitz/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
extends: ['react-app', 'plugin:jsx-a11y/recommended'],
plugins: ['jsx-a11y'],
rules: {
"import/no-anonymous-default-export": "error",
'import/no-webpack-loader-syntax': 'off',
'react/react-in-jsx-scope': 'off', // React is always in scope with Blitz
'jsx-a11y/anchor-is-valid': 'off', //Doesn't play well with Blitz/Next <Link> usage
},
}
53 changes: 53 additions & 0 deletions docs/examples/blitz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# dependencies
node_modules
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*
.npm
web_modules/

# blitz
/.blitz/
/.next/
.now
.blitz-console-history
blitz-log.log

# misc
.DS_Store

# local env files
.envrc
.env.local
.env.development.local
.env.test.local
.env.production.local

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Testing
coverage
*.lcov
.nyc_output
lib-cov

# Caches
*.tsbuildinfo
.eslintcache
.node_repl_history
.yarn-integrity

# Serverless directories
.serverless/

# Stores VSCode versions used for testing VSCode extensions
.vscode-test
1 change: 1 addition & 0 deletions docs/examples/blitz/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-exact=true
5 changes: 5 additions & 0 deletions docs/examples/blitz/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.gitkeep
.env*
*.ico
*.lock
db/migrations
42 changes: 41 additions & 1 deletion docs/examples/blitz/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
# Blitz example for Prisma-multi-tenant

TODO
This is an example project to run Blitz with the Prisma-multi-tenant plugin. (See also the tutorial "[Adding multi-tenancy to your Blitz app](/docs/integrations/Blitz.md)")

## Installation

```sh
npm install
npm run start
```

Go to http://localhost:3000/projects and see the list of projects.

Then, go to `blitz.config.js`, and change the tenant name to `"prod"`:

```js
multiTenantMiddleware((req) => {
return "prod"
})
```

Finally, **restart the server** and return see the list of projects at http://localhost:3000/projects

## Commands you can try

This will list the available tenants:

```sh
pmt list # or prisma-multi-tenant list
```

This will open studio for the tenants (dev & prod):

```sh
pmt studio dev
pmt studio prod
```

This will make you create a new tenant:

```sh
pmt new
```
Empty file.
21 changes: 21 additions & 0 deletions docs/examples/blitz/app/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react"

export default class ErrorBoundary extends React.Component<{
fallback: (error: any) => React.ReactNode
}> {
state = { hasError: false, error: null }

static getDerivedStateFromError(error: any) {
return {
hasError: true,
error,
}
}

render() {
if (this.state.hasError) {
return this.props.fallback(this.state.error)
}
return this.props.children
}
}
Empty file.
5 changes: 5 additions & 0 deletions docs/examples/blitz/app/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AppProps } from 'blitz'

export default function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
23 changes: 23 additions & 0 deletions docs/examples/blitz/app/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Document, Html, DocumentHead, Main, BlitzScript /*DocumentContext*/} from 'blitz'

class MyDocument extends Document {
// Only uncomment if you need to customize this behaviour
// static async getInitialProps(ctx: DocumentContext) {
// const initialProps = await Document.getInitialProps(ctx)
// return {...initialProps}
// }

render() {
return (
<Html lang="en">
<DocumentHead />
<body>
<Main />
<BlitzScript />
</body>
</Html>
)
}
}

export default MyDocument
197 changes: 197 additions & 0 deletions docs/examples/blitz/app/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import { Head, Link } from "blitz"

const Home = () => (
<div className="container">
<Head>
<title>blitz-app</title>
<link rel="icon" href="/favicon.ico" />
</Head>

<main>
<div className="logo">
<img src="/logo.png" alt="blitz.js" />
</div>
<p>1. Run this command in your terminal:</p>
<pre>
<code>blitz generate all project name:string</code>
</pre>
<p>2. Then run this command:</p>
<pre>
<code>blitz db migrate</code>
</pre>

<p>
3. Go to{" "}
<Link href="/projects">
<a>/projects</a>
</Link>
</p>
<div className="buttons">
<a
className="button"
href="https://github.com/blitz-js/blitz/blob/master/USER_GUIDE.md?utm_source=blitz-new&utm_medium=app-template&utm_campaign=blitz-new"
target="_blank"
rel="noopener noreferrer"
>
Documentation
</a>
<a
className="button-outline"
href="https://github.com/blitz-js/blitz"
target="_blank"
rel="noopener noreferrer"
>
Github Repo
</a>
<a
className="button-outline"
href="https://slack.blitzjs.com"
target="_blank"
rel="noopener noreferrer"
>
Slack Community
</a>
</div>
</main>

<footer>
<a
href="https://blitzjs.com?utm_source=blitz-new&utm_medium=app-template&utm_campaign=blitz-new"
target="_blank"
rel="noopener noreferrer"
>
Powered by Blitz.js
</a>
</footer>

<style jsx>{`
.container {
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
main {
padding: 5rem 0;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
main p {
font-size: 1.2rem;
}
footer {
width: 100%;
height: 60px;
border-top: 1px solid #eaeaea;
display: flex;
justify-content: center;
align-items: center;
background-color: #45009d;
}
footer a {
display: flex;
justify-content: center;
align-items: center;
}
footer a {
color: #f4f4f4;
text-decoration: none;
}
.logo {
margin-bottom: 2rem;
}
.logo img {
width: 300px;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 0.5rem;
margin-top: 6rem;
}
a.button {
background-color: #6700eb;
padding: 1rem 2rem;
color: #f4f4f4;
text-align: center;
}
a.button:hover {
background-color: #45009d;
}
a.button-outline {
border: 2px solid #6700eb;
padding: 1rem 2rem;
color: #6700eb;
text-align: center;
}
a.button-outline:hover {
border-color: #45009d;
color: #45009d;
}
pre {
background: #fafafa;
border-radius: 5px;
padding: 0.75rem;
}
code {
font-size: 0.9rem;
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
Bitstream Vera Sans Mono, Courier New, monospace;
}
.grid {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
max-width: 800px;
margin-top: 3rem;
}
@media (max-width: 600px) {
.grid {
width: 100%;
flex-direction: column;
}
}
`}</style>

<style jsx global>{`
@import url("https://fonts.googleapis.com/css2?family=Libre+Franklin:wght@300;700&display=swap");
html,
body {
padding: 0;
margin: 0;
font-family: "Libre Franklin", -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}
* {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
box-sizing: border-box;
}
`}</style>
</div>
)

export default Home
Loading

0 comments on commit 012c835

Please sign in to comment.