Skip to content

Commit

Permalink
Merge branch 'canary' into example/with-typescript-graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
piglovesyou committed Dec 22, 2019
2 parents a2d128c + 0347609 commit 6b80976
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 61 deletions.
3 changes: 2 additions & 1 deletion examples/custom-server-reasonml/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ lib/bs
*.mliast
.vscode
.merlin
.bsb.lock
.bsb.lock
node_modules
57 changes: 45 additions & 12 deletions examples/custom-server-reasonml/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
# Custom server REASONML
# Custom server ReasonML example

# Install it and run:
## How to use

### Using `create-next-app`

Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example:

```bash
npx create-next-app --example custom-server-reasonml custom-server-reasonml-app
# or
yarn create next-app --example custom-server-reasonml custom-server-reasonml-app
```

### Download manually

Download the example:

```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/custom-server-reasonml
cd custom-server-reasonml
```

### Run the development app

Install it and run:

```bash
npm install
Expand All @@ -10,26 +33,36 @@ yarn
yarn dev
```

# Build the app
### Build the app

```bash
yarn next:build
npm run next:build
# or
yarn next:build
```

# Run the production app
### Run the production app

Run this command after yarn build.
Run this command after building:

```bash
npm start
# or
yarn start
```

# The idea behind this example
### Deploy the app

Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))

```bash
now
```

## The idea behind this example

ReasonML is an exciting new language and since it can compile directly to JS via bucklescript
that means that we can power our backend server with REASONML and also have the frontend built with
reasonreact, which is covered in another [example](https://github.com/zeit/next.js/tree/canary/examples/with-reasonml).
This example shows how powerful & helpful it can be to build a next js custom server with a typesafe language.
ReasonML is an exciting new language. Since it can compile directly to JS via [BuckleScript](https://bucklescript.github.io/en/),
we can power our backend server with ReasonML and also build the frontend with
[ReasonReact](https://reasonml.github.io/reason-react/en/) (covered in the [with-reasonml example](https://github.com/zeit/next.js/tree/canary/examples/with-reasonml)).

The example has been built off the `custom-server` example that uses pure `nodejs` to build the custom server.
This example shows how powerful and helpful it is to build a Next.js custom server with a typesafe language. It is based off the [custom-server example](https://github.com/zeit/next.js/tree/canary/examples/custom-server) that uses pure Node.js to build the custom server.
4 changes: 2 additions & 2 deletions examples/custom-server-reasonml/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "custom-server-reason",
"name": "custom-server-reasonml",
"version": "0.1.0",
"scripts": {
"clean": "bsb -clean-world",
Expand All @@ -16,7 +16,7 @@
"author": "",
"license": "MIT",
"devDependencies": {
"bs-platform": "^4.0.18"
"bs-platform": "^7.0.1"
},
"dependencies": {
"cross-env": "^5.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-server-reasonml/server/http.re
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ external createServer: ((Request.t, Response.t) => unit) => http = "";

[@bs.send.pipe: http] external listen: (int, string => unit) => unit = "";

[@bs.module "url"] external parse: (string, bool) => parsedObjectUrl = "";
[@bs.module "url"] external parse: (string, bool) => parsedObjectUrl = "parse";
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
declare module 'electron-next' {
function adjustRenderer(directory: string): void

function devServer(dir: string, port?: number): void

interface Directories {
production: string
development: string
Expand All @@ -11,5 +7,5 @@ declare module 'electron-next' {
export default function(
directories: Directories | string,
port?: number
): adjustRenderer | devServer
): Promise<void>
}
2 changes: 1 addition & 1 deletion examples/with-electron-typescript/electron-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ app.on('ready', async () => {
const url = isDev
? 'http://localhost:8000/'
: format({
pathname: join(__dirname, '../renderer/index.html'),
pathname: join(__dirname, '../renderer/out/index.html'),
protocol: 'file:',
slashes: true,
})
Expand Down
32 changes: 16 additions & 16 deletions examples/with-electron-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@
"version": "1.0.0",
"main": "main/index.js",
"scripts": {
"clean": "rimraf dist main renderer/out renderer/.next",
"start": "electron .",
"build-renderer": "next build renderer && next export renderer",
"build-electron": "tsc -p electron-src",
"build": "yarn build-renderer && yarn build-electron",
"dist": "npm run build && electron-builder --dir",
"pack-app": "yarn build && electron-builder --dir",
"dist": "yarn build && electron-builder",
"type-check": "tsc"
},
"build": {
"asar": false,
"extraResources": [
{
"from": "renderer/out",
"to": "app/renderer"
}
"asar": true,
"files": [
"main",
"renderer/out"
]
},
"devDependencies": {
"@types/next": "8.0.6",
"@types/node": "^11.13.9",
"@types/react": "^16.8.15",
"@types/react-dom": "^16.0.11",
"electron": "^6.0.2",
"@types/node": "^12.12.21",
"@types/react": "^16.9.17",
"@types/react-dom": "^16.9.4",
"electron": "^7.1.7",
"electron-builder": "^21.2.0",
"next": "latest",
"typescript": "^3.5.3"
"rimraf": "^3.0.0",
"typescript": "^3.7.4"
},
"dependencies": {
"electron-is-dev": "^1.0.1",
"electron-is-dev": "^1.1.0",
"electron-next": "^3.1.5",
"react": "^16.7.0",
"react-dom": "^16.7.0"
"react": "^16.12.0",
"react-dom": "^16.12.0"
}
}
4 changes: 2 additions & 2 deletions examples/with-electron/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ app.on('ready', async () => {
})

const url = isDev
? 'http://localhost:8000/start'
? 'http://localhost:8000'
: format({
pathname: join(__dirname, '../renderer/start.html'),
pathname: join(__dirname, '../renderer/out/index.html'),
protocol: 'file:',
slashes: true,
})
Expand Down
22 changes: 11 additions & 11 deletions examples/with-electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
"version": "1.0.0",
"main": "main/index.js",
"scripts": {
"clean": "rimraf dist renderer/.next renderer/out",
"start": "electron .",
"build": "next build renderer && next export renderer",
"dist": "npm run build && electron-builder --dir"
"pack-app": "npm run build && electron-builder --dir",
"dist": "npm run build && electron-builder"
},
"build": {
"asar": false,
"extraResources": [
{
"from": "renderer/out",
"to": "app/renderer"
}
"asar": true,
"files": [
"main",
"renderer/out"
]
},
"devDependencies": {
"electron": "^6.0.2",
"electron": "^7.1.7",
"electron-builder": "^21.2.0",
"next": "latest",
"react": "^16.8.4",
"react-dom": "^16.8.4"
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
"dependencies": {
"electron-is-dev": "^1.0.1",
"electron-is-dev": "^1.1.0",
"electron-next": "^3.1.5"
}
}
10 changes: 0 additions & 10 deletions examples/with-electron/renderer/next.config.js

This file was deleted.

0 comments on commit 6b80976

Please sign in to comment.