Skip to content

Commit

Permalink
Merge pull request #2 from redwoodjs/main
Browse files Browse the repository at this point in the history
update to 0.31.0
  • Loading branch information
viperfx authored May 2, 2021
2 parents 2de6be3 + b78cff8 commit 8de2fdb
Show file tree
Hide file tree
Showing 324 changed files with 28,882 additions and 6,334 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build-eslint-jest.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Lint, build and run tests

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]

Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Cypress E2E tests

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-npm-canary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [main]
tags-ignore:
- v**
- v** # We don't want this to run on release

jobs:
build:
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/publish-npm-rc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish release candidate

on:
push:
branches: ['release/**']
tags-ignore:
- v** # We don't want this to run on release

jobs:
build:
if: github.repository == 'redwoodjs/redwood'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Required because lerna uses tags to determine the version.

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Install dependencies
run: yarn install --frozen-lockfile --check-files

- name: Build
run: yarn build

- name: Run ESLint
run: yarn lint
env:
CI: true

- name: Run tests
run: yarn test
env:
CI: true

- name: Publish
run: |
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc
./tasks/publish-rc
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
File renamed without changes.
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This Code of Conduct applies within all community spaces, and also applies when

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting Tom Preston-Werner [[email protected]](mailto:[email protected]), Peter Pistorius [[email protected]]([email protected]), and/or Rob Cameron [[email protected]]([email protected]). All complaints will be reviewed and investigated promptly and fairly.
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting Tom Preston-Werner [[email protected]](mailto:[email protected]), Peter Pistorius [[email protected]]([email protected]), Rob Cameron [[email protected]](cannikin@fastmail.com), and/or [David Price](thedavid@thedavidprice.com). All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the reporter of any incident.

Expand Down
195 changes: 146 additions & 49 deletions CONTRIBUTING.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Redwood
Copyright (c) 2021 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
Expand Down
5 changes: 2 additions & 3 deletions __fixtures__/example-todo-main/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ generator photonjs {

// Define your own models here and run `yarn rw db save` to create
// migrations for them.

model Todo {
id Int @id @default(autoincrement())
id Int @default(autoincrement()) @id
body String @unique
status String @default("off")
}
}
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ const TARGETS_BROWSERS = ['defaults', 'not IE 11', 'not IE_Mob 11']
// instead of corejs: '3', since with '3' it will not be injected modules
// which were added in minor core-js releases.
// https://github.com/zloirock/core-js/blob/master/README.md#babelpreset-env
const CORE_JS_VERSION = '3.6'
const CORE_JS_VERSION = '3.10'

// We use the recommended babel configuration for monorepos, which is a base directory
// `babel.config.js` file, but then use a per-project `.babelrc.js` file.
// Learn more: https://babeljs.io/docs/en/config-files#monorepos
/** @type {import('@babel/core').TransformOptions} */
module.exports = {
presets: [
[
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.27.1",
"version": "0.31.0",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
Expand Down
48 changes: 25 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"build:types": "ttsc --build --verbose",
"build:clean": "rimraf ./packages/**/dist",
"build:watch": "lerna run build:watch --parallel; ttsc --build",
"build:link": "./tasks/build-link",
"test": "lerna run test --stream -- --colors --maxWorkers=4",
"lint": "eslint -c .eslintrc.js packages",
"lint:fix": "eslint -c .eslintrc.js --fix packages"
"lint": "cross-env __REDWOOD__CONFIG_PATH=packages/create-redwood-app/template eslint -c .eslintrc.js packages",
"lint:fix": "cross-env __REDWOOD__CONFIG_PATH=packages/create-redwood-app/template eslint -c .eslintrc.js --fix packages"
},
"private": true,
"license": "MIT",
Expand All @@ -16,43 +17,44 @@
"packages/*"
],
"devDependencies": {
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@babel/node": "^7.10.5",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-decorators": "^7.10.5",
"@babel/plugin-transform-runtime": "^7.11.5",
"@babel/preset-env": "^7.11.5",
"@babel/preset-react": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@babel/runtime-corejs3": "^7.11.2",
"@testing-library/jest-dom": "5.11.6",
"@testing-library/react": "11.2.2",
"@testing-library/user-event": "12.5.0",
"@types/jest": "^26.0.14",
"@babel/cli": "7.13.14",
"@babel/core": "7.13.16",
"@babel/node": "7.13.13",
"@babel/plugin-proposal-class-properties": "7.13.0",
"@babel/plugin-proposal-decorators": "7.13.15",
"@babel/plugin-transform-runtime": "7.13.15",
"@babel/preset-env": "7.13.15",
"@babel/preset-react": "7.13.13",
"@babel/preset-typescript": "7.13.0",
"@babel/runtime-corejs3": "7.13.10",
"@testing-library/jest-dom": "5.11.10",
"@testing-library/react": "11.2.6",
"@testing-library/user-event": "13.1.6",
"@types/jest": "^26.0.23",
"babel-jest": "^26.5.2",
"babel-plugin-auto-import": "^1.1.0",
"babel-plugin-module-resolver": "^4.0.0",
"babel-plugin-remove-code": "^0.0.6",
"core-js": "3.6.5",
"babel-plugin-auto-import": "1.1.0",
"babel-plugin-module-resolver": "4.1.0",
"babel-plugin-remove-code": "0.0.6",
"core-js": "3.10.1",
"cp-cli": "^2.0.0",
"cross-env": "^7.0.2",
"jest": "^26.5.3",
"lerna": "^3.20.2",
"msw": "0.21.2",
"nodemon": "^2.0.6",
"npm-packlist": "^2.1.5",
"rimraf": "^3.0.2",
"ttypescript": "^1.5.12",
"typescript": "^4.1.3",
"typescript": "^4.2.4",
"typescript-transform-paths": "^2.2.2",
"whatwg-fetch": "3.4.1"
},
"resolutions": {
"@types/react": "17.0.2",
"@types/react": "17.0.3",
"prop-types": "15.7.2",
"react-dom": "17.0.1",
"react": "17.0.1",
"typescript": "4.1.3",
"typescript": "4.2.4",
"vscode-languageserver-protocol": "3.15.3",
"vscode-languageserver-types": "3.15.1",
"vscode-languageserver": "6.1.1",
Expand Down
8 changes: 5 additions & 3 deletions packages/api-server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@redwoodjs/api-server",
"description": "Redwood's HTTP server for Serverless Functions",
"version": "0.27.1",
"version": "0.31.0",
"bin": {
"api-server": "./dist/index.js",
"rw-api-server": "./dist/index.js",
Expand All @@ -10,22 +10,24 @@
"files": [
"dist"
],
"main": "dist/handler",
"license": "MIT",
"dependencies": {
"body-parser": "^1.19.0",
"chokidar": "3.5.1",
"dotenv-defaults": "2.0.1",
"express": "^4.17.1",
"glob": "7.1.6",
"http-proxy-middleware": "^1.1.0",
"lodash.escape": "^4.0.1",
"morgan": "^1.10.0",
"qs": "^6.9.3",
"yargs": "^16.0.3",
"youch": "^2.1.1",
"youch": "^2.2.1",
"youch-terminal": "^1.0.1"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.46",
"@types/aws-lambda": "^8.10.76",
"@types/express": "^4.17.3",
"@types/lodash.escape": "^4.0.6",
"@types/morgan": "^1.9.0",
Expand Down
15 changes: 15 additions & 0 deletions packages/api-server/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import express from 'express'
import type { Response, Request, Application } from 'express'
import morgan from 'morgan'

// Base express app, with common config
const createApp = (): Application => {
const app = express()

// Add common middleware
app.use(morgan<Request, Response>('dev'))

return app
}

export default createApp
129 changes: 129 additions & 0 deletions packages/api-server/src/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { getConfig } from '@redwoodjs/internal'

import createApp from './app'
import withApiProxy from './middleware/withApiProxy'
import withFunctions from './middleware/withFunctions'
import withWebServer from './middleware/withWebServer'
import { startServer } from './server'
import type { HttpServerParams } from './server'

/*
* This file has defines CLI handlers used by the redwood cli, for `rw serve`
* Also used in index.ts for the api server
*/

export const commonOptions = {
port: { default: 8910, type: 'number', alias: 'p' },
socket: { type: 'string' },
} as const

export const apiCliOptions = {
port: { default: 8911, type: 'number', alias: 'p' },
socket: { type: 'string' },
apiRootPath: {
alias: ['rootPath', 'root-path'],
default: '/',
type: 'string',
desc: 'Root path where your api functions are served',
coerce: coerceRootPath,
},
} as const

export const webCliOptions = {
port: { default: 8910, type: 'number', alias: 'p' },
socket: { type: 'string' },
apiHost: {
alias: 'api-host',
type: 'string',
desc:
'Forward requests from the apiProxyPath, defined in redwood.toml to this host',
},
} as const

interface ApiServerArgs extends Omit<HttpServerParams, 'app'> {
apiRootPath: string // either user supplied or '/'
}

export const apiServerHandler = ({
port,
socket,
apiRootPath,
}: ApiServerArgs) => {
let app = createApp()

// Attach middleware
app = withFunctions(app, apiRootPath)

startServer({
port,
socket,
app,
}).on('listening', () => {
if (socket) {
console.log(`Listening on ${socket}`)
}
console.log(`Listening on http://localhost:${port}${apiRootPath}`)
})
}

export const bothServerHandler = ({
port,
socket,
}: Omit<HttpServerParams, 'app'>) => {
const apiRootPath = coerceRootPath(getConfig().web.apiProxyPath)
let app = createApp()

// Attach middleware
app = withFunctions(app, apiRootPath)
app = withWebServer(app)

startServer({
port,
socket,
app,
}).on('listening', () => {
if (socket) {
console.log(`Listening on ${socket}`)
}

console.log(`Web server started on http://localhost:${port} `)
console.log(`APIs Listening on http://localhost:${port}${apiRootPath}`)
})
}

interface WebServerArgs extends Omit<HttpServerParams, 'app'> {
apiHost?: string
}

export const webServerHandler = ({ port, socket, apiHost }: WebServerArgs) => {
let app = createApp()

// Attach middleware
// We need to proxy api requests to prevent CORS issues
if (apiHost) {
const apiProxyPath = getConfig().web.apiProxyPath
app = withApiProxy(app, { apiHost, apiProxyPath })
}

app = withWebServer(app)

startServer({
port,
socket,
app,
}).on('listening', () => {
if (socket) {
console.log(`Listening on ${socket}`)
}

console.log(`Web server started on http://localhost:${port} `)
})
}

function coerceRootPath(path: string) {
// Make sure that we create a root path that starts and ends with a slash (/)
const prefix = path.charAt(0) !== '/' ? '/' : ''
const suffix = path.charAt(path.length - 1) !== '/' ? '/' : ''

return `${prefix}${path}${suffix}`
}
Loading

0 comments on commit 8de2fdb

Please sign in to comment.