-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy redwoodjs example from vercel/vercel (#1026)
- Loading branch information
1 parent
5b48785
commit a1a148a
Showing
38 changed files
with
15,674 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# These environment variables will be used by default if you do not create any | ||
# yourself in .env. This file should be safe to check into your version control | ||
# system. Any custom values should go in .env and .env should *not* be checked | ||
# into version control. | ||
|
||
# schema.prisma defaults | ||
DATABASE_URL=file:./dev.db | ||
|
||
# location of the test database for api service scenarios (defaults to ./.redwood/test.db if not set) | ||
# TEST_DATABASE_URL=file:./.redwood/test.db | ||
|
||
# disables Prisma CLI update notifier | ||
PRISMA_HIDE_UPDATE_MESSAGE=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.idea | ||
.DS_Store | ||
.env | ||
.netlify | ||
.redwood | ||
dev.db | ||
dist | ||
dist-babel | ||
node_modules | ||
yarn-error.log | ||
web/public/mockServiceWorker.js | ||
|
||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Redwood | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
![RedwoodJS Logo](https://github.com/vercel/vercel/blob/main/packages/frameworks/logos/redwoodjs.svg) | ||
|
||
# RedwoodJS Example | ||
|
||
This directory is a brief example of a [RedwoodJS](https://redwoodjs.com) app with [Serverless Functions](https://vercel.com/docs/concepts/functions/serverless-functions) that can be deployed to Vercel with zero configuration. | ||
|
||
## Deploy Your Own | ||
|
||
Deploy your own RedwoodJS project, along with Serverless Functions, with Vercel. | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/examples/tree/main/framework-boilerplates/redwoodjs&template=redwoodjs) | ||
|
||
_Live Example: https://redwood-template.vercel.app_ | ||
|
||
### How We Created This Example | ||
|
||
To get started with RedwoodJS on Vercel, you can [use Yarn to initialize](https://redwoodjs.com/tutorial/installation-starting-development) the project: | ||
|
||
```shell | ||
$ yarn create redwood-app ./my-redwood-app | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = { extends: '../babel.config.js' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
datasource DS { | ||
provider = "sqlite" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
binaryTargets = "native" | ||
} | ||
|
||
// Define your own datamodels here and run `yarn redwood prisma migrate dev` | ||
// to create migrations for them and apply to your dev DB. | ||
// TODO: Please remove the following example: | ||
model UserExample { | ||
id Int @id @default(autoincrement()) | ||
email String @unique | ||
name String? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint-disable no-console */ | ||
const { PrismaClient } = require('@prisma/client') | ||
const dotenv = require('dotenv') | ||
|
||
dotenv.config() | ||
const db = new PrismaClient() | ||
|
||
async function main() { | ||
// https://www.prisma.io/docs/guides/prisma-guides/seed-database | ||
// | ||
// Seed data is database data that needs to exist for your app to run. | ||
// Ideally this file should be idempotent: running it multiple times | ||
// will result in the same database state (usually by checking for the | ||
// existence of a record before trying to create it). For example: | ||
// | ||
// const existing = await db.user.findMany({ where: { email: 'admin@email.com' }}) | ||
// if (!existing.length) { | ||
// await db.user.create({ data: { name: 'Admin', email: 'admin@email.com' }}) | ||
// } | ||
|
||
console.info('No data to seed. See api/db/seed.js for info.') | ||
} | ||
|
||
main() | ||
.catch((e) => console.error(e)) | ||
.finally(async () => { | ||
await db.$disconnect() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const { getConfig } = require('@redwoodjs/core') | ||
|
||
const config = getConfig({ type: 'jest', target: 'node' }) | ||
config.displayName.name = 'api' | ||
|
||
module.exports = config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"src/*": ["./src/*"] | ||
} | ||
}, | ||
"include": ["src/**/*", "../.redwood/index.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "api", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@redwoodjs/api": "^0.25.0" | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
framework-boilerplates/redwoodjs/api/src/functions/graphql.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { | ||
createGraphQLHandler, | ||
makeMergedSchema, | ||
makeServices, | ||
} from '@redwoodjs/api' | ||
|
||
import schemas from 'src/graphql/**/*.{js,ts}' | ||
import { db } from 'src/lib/db' | ||
import services from 'src/services/**/*.{js,ts}' | ||
|
||
export const handler = createGraphQLHandler({ | ||
schema: makeMergedSchema({ | ||
schemas, | ||
services: makeServices({ services }), | ||
}), | ||
onException: () => { | ||
// Disconnect from your database with an unhandled exception. | ||
db.$disconnect() | ||
}, | ||
}) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// See https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/constructor | ||
// for options. | ||
|
||
import { PrismaClient } from '@prisma/client' | ||
|
||
export const db = new PrismaClient() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: ['@redwoodjs/core/config/babel-preset'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { getConfig } = require('@redwoodjs/internal') | ||
|
||
const config = getConfig() | ||
|
||
module.exports = { | ||
schema: `http://${config.api.host}:${config.api.port}/graphql`, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"private": true, | ||
"workspaces": { | ||
"packages": [ | ||
"api", | ||
"web", | ||
"packages/*" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@redwoodjs/core": "^0.25.0" | ||
}, | ||
"eslintConfig": { | ||
"extends": "@redwoodjs/eslint-config" | ||
}, | ||
"engines": { | ||
"node": "16.x", | ||
"yarn": ">=1.15" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// https://prettier.io/docs/en/options.html | ||
module.exports = { | ||
trailingComma: 'es5', | ||
bracketSpacing: true, | ||
tabWidth: 2, | ||
semi: false, | ||
singleQuote: true, | ||
arrowParens: 'always', | ||
overrides: [ | ||
{ | ||
files: 'Routes.js', | ||
options: { | ||
printWidth: 200, | ||
}, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This file contains the configuration settings for your Redwood app. | ||
# This file is also what makes your Redwood app a Redwood app. | ||
# If you remove it and try to run `yarn rw dev`, you'll get an error. | ||
# | ||
# For the full list of options, see the "App Configuration: redwood.toml" doc: | ||
# https://redwoodjs.com/docs/app-configuration-redwood-toml | ||
|
||
[web] | ||
port = 8910 | ||
apiProxyPath = "/api" | ||
[api] | ||
port = 8911 | ||
schemaPath = "./api/db/schema.prisma" | ||
[browser] | ||
open = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = { extends: '../babel.config.js' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const { getConfig } = require('@redwoodjs/core') | ||
|
||
const config = getConfig({ type: 'jest', target: 'browser' }) | ||
config.displayName.name = 'web' | ||
|
||
module.exports = config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"src/*": ["./src/*"] | ||
}, | ||
"jsx": "preserve" | ||
}, | ||
"include": ["src/**/*", "../.redwood/index.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "web", | ||
"version": "0.0.0", | ||
"private": true, | ||
"browserslist": { | ||
"development": [ | ||
"last 1 version" | ||
], | ||
"production": [ | ||
"defaults", | ||
"not IE 11", | ||
"not IE_Mob 11" | ||
] | ||
}, | ||
"dependencies": { | ||
"@redwoodjs/forms": "^0.25.0", | ||
"@redwoodjs/router": "^0.25.0", | ||
"@redwoodjs/web": "^0.25.0", | ||
"prop-types": "^15.7.2", | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Static Assets | ||
|
||
Use this folder to add static files directly to your app. All included files and folders will be copied directly into the `/dist` folder (created when Webpack builds for production). They will also be available during development when you run `yarn rw dev`. | ||
|
||
> Note: files will _not_ hot reload while the development server is running. You'll need to manually stop/start to access file changes. | ||
### Example Use | ||
|
||
A file like `favicon.png` will be copied to `/dist/favicon.png`. A folder containing a file such as `static-files/my-logo.jpg` will be copied to `/dist/static-files/my-logo.jpg`. These can be referenced in your code directly without any special handling, e.g. | ||
|
||
``` | ||
<link rel="icon" type="image/png" href="/favicon.png" /> | ||
``` | ||
|
||
and | ||
|
||
``` | ||
<img src="/static-files/my-logo.jpg"> alt="Logo" /> | ||
``` | ||
|
||
Behind the scenes, we are using Webpack's ["copy-webpack-plugin"](https://github.com/webpack-contrib/copy-webpack-plugin). | ||
|
||
## Best Practices | ||
|
||
Because assets in this folder are bypassing the javascript module system, **this folder should be used sparingly** for assets such as favicons, robots.txt, manifests, libraries incompatible with Webpack, etc. | ||
|
||
In general, it's best to import files directly into a template, page, or component. This allows Webpack to include that file in the bundle, which ensures Webpack will correctly process and move assets into the distribution folder, providing error checks and correct paths along the way. | ||
|
||
### Example Asset Import with Webpack | ||
|
||
Instead of handling our logo image as a static file per the example above, we can do the following: | ||
|
||
``` | ||
import React from "react" | ||
import logo from "./my-logo.jpg" | ||
function Header() { | ||
return <img src={logo} alt="Logo" /> | ||
} | ||
export default Header | ||
``` | ||
|
||
Behind the scenes, we are using Webpack's ["file-loader"](https://webpack.js.org/loaders/file-loader/) and ["url-loader](https://webpack.js.org/loaders/url-loader/) (for files smaller than 10kb). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
User-agent: * | ||
Disallow: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// In this file, all Page components from 'src/pages` are auto-imported. Nested | ||
// directories are supported, and should be uppercase. Each subdirectory will be | ||
// prepended onto the component name. | ||
// | ||
// Examples: | ||
// | ||
// 'src/pages/HomePage/HomePage.js' -> HomePage | ||
// 'src/pages/Admin/BooksPage/BooksPage.js' -> AdminBooksPage | ||
|
||
import { Router, Route } from '@redwoodjs/router' | ||
|
||
const Routes = () => { | ||
return ( | ||
<Router> | ||
<Route path="/" page={HomePage} name="home" /> | ||
<Route path="/about" page={AboutPage} name="about" /> | ||
<Route notfound page={NotFoundPage} /> | ||
</Router> | ||
) | ||
} | ||
|
||
export default Routes |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="icon" type="image/png" href="/favicon.png" /> | ||
<title><%= htmlWebpackPlugin.options.title %></title> | ||
</head> | ||
<body> | ||
<div id="redwood-app"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import ReactDOM from 'react-dom' | ||
|
||
import { FatalErrorBoundary } from '@redwoodjs/web' | ||
import { RedwoodApolloProvider } from '@redwoodjs/web/apollo' | ||
|
||
import FatalErrorPage from 'src/pages/FatalErrorPage' | ||
import Routes from 'src/Routes' | ||
|
||
import './index.css' | ||
|
||
ReactDOM.render( | ||
<FatalErrorBoundary page={FatalErrorPage}> | ||
<RedwoodApolloProvider> | ||
<Routes /> | ||
</RedwoodApolloProvider> | ||
</FatalErrorBoundary>, | ||
document.getElementById('redwood-app') | ||
) |
Empty file.
Oops, something went wrong.