Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implemented Remix server adapter and runtime for Netlify #16

Merged
merged 43 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e141d98
feat: implemented Remix server adapter and runtime for Netlify
nickytonline Jan 26, 2023
8e56897
chore: added the demo edge site to test the Netlify remix server adapter
nickytonline Jan 27, 2023
79bb70d
chore: added default remix config for the Netlify adapter
nickytonline Jan 27, 2023
379fcf9
chore: remove extension from import
nickytonline Jan 27, 2023
c5b3b36
chore: added some more defaults to the default remix config
nickytonline Jan 27, 2023
2faaffa
Update packages/remix-server-adapter/src/globals.ts
nickytonline Jan 27, 2023
4bc07ea
chore: renamed '@netlify/remix-server-adapter to @netlify/remix-adapter
nickytonline Jan 27, 2023
569bc20
chore: fixed globals
nickytonline Jan 27, 2023
959a30b
chore: forgot to commit updated package lock
nickytonline Jan 27, 2023
a58e06e
chore: configured project to deploy edge demo site
nickytonline Jan 27, 2023
853ac97
chore: renamed remix-server-runtime to remix-runtime
nickytonline Jan 30, 2023
cb6cdee
chore: renamed remix-adapter to remix-edge-adapter
nickytonline Jan 30, 2023
21d9bf8
Merge remote-tracking branch 'origin/main' into nickytonline/add-adap…
nickytonline Jan 30, 2023
8b3cd57
Merge remote-tracking branch 'origin/main' into nickytonline/adapter-…
nickytonline Jan 31, 2023
84fdc49
Merge remote-tracking branch 'origin/main' into nickytonline/adapter-…
nickytonline Feb 3, 2023
aaaff6f
chore: fixed lint errors
nickytonline Feb 3, 2023
7b03c6c
chore: automatic prettier formatting
nickytonline Feb 3, 2023
1007d4d
chore: avoid husky in CI
nickytonline Feb 3, 2023
a0038db
chore: avoid husky in CI (again)
nickytonline Feb 3, 2023
f570e9c
Merge remote-tracking branch 'origin/main' into nickytonline/add-adap…
nickytonline Feb 3, 2023
9974faa
test: added E2E tests
nickytonline Feb 6, 2023
7b0970a
chore: react 18 hydration errors in Cypress handled now
nickytonline Feb 6, 2023
360b94b
chore: clarified a comment
nickytonline Feb 6, 2023
6f258da
chore: added GH workflow for Cypress
nickytonline Feb 6, 2023
e0b4e65
chore: trying an if-env fix again
nickytonline Feb 6, 2023
3b2e8cc
Merge remote-tracking branch 'origin/main' into nickytonline/add-adap…
nickytonline Feb 6, 2023
e9927b0
chore: fixed build setup for git push deploy
nickytonline Feb 7, 2023
4333b20
chore: fixed edge functions path
nickytonline Feb 7, 2023
f788018
chore: fixed a typo in Cypress YAML config 🙃
nickytonline Feb 7, 2023
c443950
chore: added ReadME for @netlify/remix-runtime
nickytonline Feb 7, 2023
0c15673
chore: added ReadME for @netlify/remix-edge-adapter
nickytonline Feb 7, 2023
ce64771
chore: updated ReadME for edge demo site
nickytonline Feb 7, 2023
af313d0
chore: first attempt at project README
nickytonline Feb 7, 2023
67fe4d4
chore: changed script names from compile to build
nickytonline Feb 7, 2023
cfb4cbd
chore: added the build:watch script
nickytonline Feb 7, 2023
8676091
chore: set Cypress containers to 1 as we only spec file atm
nickytonline Feb 8, 2023
9ce4b79
chore: added a comment about the demo site's server build path
nickytonline Feb 8, 2023
27c4b51
Update README.md
nickytonline Feb 8, 2023
cd4d261
chore: corrected Netlify Edge functions links and referenced the prod…
nickytonline Feb 8, 2023
daafe3f
chore: set cache-control to 60 seconds for the demo site
nickytonline Feb 8, 2023
f616d4f
chore: added the x-nf-runtime header to responses returned from our r…
nickytonline Feb 8, 2023
993a262
chore: corrected what the product is called
nickytonline Feb 8, 2023
6ed4e65
Update packages/edge-demo-site/README.md
nickytonline Feb 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/cypress-edge-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Run e2e (Remix Edge Demo)
nickytonline marked this conversation as resolved.
Show resolved Hide resolved
on:
pull_request:
types: [opened, synchronize]
push:
branches:
- main
jobs:
cypress:
name: Cypress
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
containers: [1, 2]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Generate Github token
uses: navikt/github-app-token-generator@v1
id: get-token
with:
private-key: ${{ secrets.TOKENS_PRIVATE_KEY }}
app-id: ${{ secrets.TOKENS_APP_ID }}

- name: Checkout @netlify/wait-for-deploy-action
uses: actions/checkout@v2
with:
repository: netlify/wait-for-deploy-action
token: ${{ steps.get-token.outputs.token }}
path: ./.github/actions/wait-for-netlify-deploy

- name: Wait for Netlify Deploy
id: deploy
uses: ./.github/actions/wait-for-netlify-deploy
with:
site-name: remix-edge
timeout: 300

- name: Deploy successful
if: ${{ steps.deploy.outputs.origin-url }}
run: echo ${{ steps.deploy.outputs.origin-url }}

- name: Node
uses: actions/setup-node@v2
with:
node-version: '16'

- run: npm install

- name: Cypress run
if: ${{ steps.deploy.outputs.origin-url }}
id: cypress
uses: cypress-io/github-action@v2
with:
browser: chrome
headless: true
record: true
parallel: true
config-file: cypress/config/edge-cypress.config.ts
group: 'Remix Edge Demo'
env:
DEBUG: '@cypress/github-action'
CYPRESS_baseUrl: ${{ steps.deploy.outputs.origin-url }}
CYPRESS_NETLIFY_CONTEXT: ${{ steps.deploy.outputs.context }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_RECORD_KEY: ${{ secrets.REMIX_EDGE_CYPRESS_RECORD_KEY }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,8 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

build/

# Local Netlify folder
.netlify
29 changes: 11 additions & 18 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
MIT License Copyright (c) 2023 Nick Taylor
nickytonline marked this conversation as resolved.
Show resolved Hide resolved
MIT License Copyright (c) 2023 Netlify Inc.

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:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
nickytonline marked this conversation as resolved.
Show resolved Hide resolved
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
(including the next paragraph) shall be included in all copies or substantial
portions of the Software.
The above copyright notice and this permission notice (including the next paragraph) 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.
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.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Remix Compute for Netlify
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind having a peek at this @stephmarie17? It's to the point, but just want to make sure about the wording.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! Clear and to the point.


The Remix Compute for Netlify packages allows you to deploy your Remix apps to Netlify on the Edge.
nickytonline marked this conversation as resolved.
Show resolved Hide resolved

This project is not a template for Remix apps. It is a set of packages used by the Netlify Remix template.

The project is a monorepo. Packages are located in the `packages` directory. There are three packages:

- `@netlify/remix-runtime` - The Remix runtime for Netlify on the Edge
nickytonline marked this conversation as resolved.
Show resolved Hide resolved
- `@netlify/remix-edge-adapter` - The Remix adapter for Netlify on the Edge
- `@netlify/remix-edge-demo-site` - A demo site for testing the packages

## Installation

```bash
npm install
```

This installs all the dependencies for all the packages and builds the `@netlify/remix-runtime` and
`@netlify/remix-edge-adapter` packages.

## Development

Run the build watch command to have packages built when they are changed.

```bash
npm run build:watch
```

When you're ready to test your changes, you can run the demo site locally.

```bash
ntl build --offline
ntl serve
```
2 changes: 2 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { defineConfig } from 'cypress'

export default defineConfig({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new Cypress config. It's what's used now instead of cypress.json, ci.json etc.

e2e: {
baseUrl: 'http://localhost:8888',
specPattern: 'cypress/e2e/**/*.spec.ts',
setupNodeEvents(on, config) {
// implement node event listeners here
},
Expand Down
12 changes: 12 additions & 0 deletions cypress/config/edge-cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from 'cypress'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the Cypress format config for the Remix Edge demo.


export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
specPattern: 'cypress/e2e/**/*.spec.ts',
projectId: 'k847hv',
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
})
9 changes: 9 additions & 0 deletions cypress/e2e/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('Smoke Test', () => {
it('Should load the demo site', () => {
cy.visit('/')
cy.findByRole('heading', { name: /Welcome to Remix/i }).should('exist')
cy.findByRole('link', { name: /15m Quickstart Blog Tutorial/i }).should('exist')
cy.findByRole('link', { name: /Deep Dive Jokes App Tutorial/i }).should('exist')
cy.findByRole('link', { name: /Remix Docs/i }).should('exist')
})
})
47 changes: 11 additions & 36 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
import '@testing-library/cypress/add-commands'

// Handles React 18 hydration errors
// The hydration errors are because Cypress is manipulating the DOM
// See https://github.com/robipop22/dnb-stack/issues/3#issuecomment-1286112365
Cypress.on('uncaught:exception', (err) => {
// we check if the error is
if (err.message.includes('Minified React error #418;') || err.message.includes('Minified React error #423;')) {
return false
}
})
3 changes: 3 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
command = "npm run build:edge-demo"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ascorbic, all the files in e9927b0 (#16) is the best setup for a deploy I could get going. Also, the change in 4333b20#diff-07374dfaf56a1e11c7f1b9216123fb94be5458e2ca11f70f170fdc9a283aee72R9.

It's a monorepo where the edge demo site requires the @netlify/remix-edge-adapter and @netlify/remix-runtime to be built first so that the edge demo site can build. I tried the cd trick with a base URL in the root netlify.toml, but couldn't get that working as the base url of packages/edge-demo-site wasn't installing all the packages for the monorepo.

That was also why I had issues with if-env and husky not being found on git push deploys. Definitely open to suggestions as I imagine at some point soon, the Netlify Functions demo site will be in here as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than the toml you could set these in the UI, which would let you use different commands and roots for each site

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good call about using different commands. The root would stay the same though as I need the monorepo to install everything. I'll make this change once we bring the Netlify Functions adapter into the project.

publish = "packages/edge-demo-site/public"
Loading