Skip to content

Commit c86821c

Browse files
timneutkenstimothyis
authored andcommitted
Upgrade Next.js, Move server to using micro cli, redirect / to /docs (#207)
* Upgrade Next, Move server to using micro cli, redirect / to /docs * Upgrade React and React DOM * Upgrade circle config to v2 * Force npm type
1 parent aa5fdb8 commit c86821c

File tree

10 files changed

+1868
-1773
lines changed

10 files changed

+1868
-1773
lines changed

Diff for: env-config.js renamed to .babelrc.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
// this file exports a bunch of replacements
2-
// that are made across the source-code
3-
4-
module.exports = {
1+
const env = {
52
VERSION: require('./package').version,
63
'process.env.NODE_ENV': process.env.NODE_ENV,
74
IMAGE_ASSETS_URL: 'https://assets.zeit.co/image/upload/front',
85
VIDEO_ASSETS_URL: 'https://assets.zeit.co/video/upload/front',
96
RAW_ASSETS_URL: 'https://assets.zeit.co/raw/upload/front'
107
}
8+
9+
module.exports = {
10+
presets: ['next/babel'],
11+
plugins: [['transform-define', env], 'markdown-in-js/babel']
12+
}

Diff for: .circleci/config.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
jobs:
3+
build:
4+
machine: true
5+
steps:
6+
- checkout
7+
- run: docker build .

Diff for: Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM mhart/alpine-node:9.11.1
2+
WORKDIR /src
3+
COPY package.json ./
4+
RUN yarn
5+
COPY . ./
6+
RUN yarn test

Diff for: circle.yml

-7
This file was deleted.

Diff for: lib/data/last-edited.json

+48-48
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
{
2-
"pages/docs/deployment-types/docker.js": "2018-05-11T13:40:09.695Z",
3-
"pages/docs/deployment-types/index.js": "2018-05-02T18:57:52.832Z",
4-
"pages/docs/deployment-types/lifecycle.js": "2018-05-02T18:57:52.832Z",
5-
"pages/docs/deployment-types/node.js": "2018-05-11T13:40:09.695Z",
6-
"pages/docs/deployment-types/static.js": "2018-05-11T13:40:09.696Z",
7-
"pages/docs/examples/chat.js": "2018-05-11T13:40:09.697Z",
8-
"pages/docs/examples/create-react-app.js": "2018-05-11T13:40:09.697Z",
9-
"pages/docs/examples/graphql.js": "2018-05-02T18:57:52.834Z",
10-
"pages/docs/examples/index.js": "2018-05-02T18:57:52.834Z",
11-
"pages/docs/examples/json-api.js": "2018-05-11T13:40:09.698Z",
12-
"pages/docs/examples/next.js": "2018-05-11T13:40:09.698Z",
13-
"pages/docs/examples/redirect.js": "2018-05-02T18:57:52.834Z",
14-
"pages/docs/examples/slack-slash.js": "2018-05-11T13:40:09.699Z",
15-
"pages/docs/examples/static.js": "2018-05-11T13:40:09.699Z",
16-
"pages/docs/examples/travis.js": "2018-05-11T13:40:09.700Z",
17-
"pages/docs/features/aliases.js": "2018-05-11T13:40:09.700Z",
18-
"pages/docs/features/certs.js": "2018-05-11T13:40:09.701Z",
19-
"pages/docs/features/configuration.js": "2018-05-11T13:40:09.701Z",
20-
"pages/docs/features/dns.js": "2018-05-11T13:40:09.702Z",
21-
"pages/docs/features/env-and-secrets.js": "2018-05-11T13:40:09.702Z",
22-
"pages/docs/features/index.js": "2018-05-02T18:57:52.836Z",
23-
"pages/docs/features/now-cli.js": "2018-05-11T13:40:09.703Z",
24-
"pages/docs/features/path-aliases.js": "2018-05-11T13:40:09.704Z",
25-
"pages/docs/features/private-npm.js": "2018-05-11T13:40:09.704Z",
26-
"pages/docs/features/repositories.js": "2018-05-11T13:40:09.705Z",
27-
"pages/docs/features/scaling.js": "2018-05-11T13:40:09.705Z",
28-
"pages/docs/features/zero-downtime-migration.js": "2018-05-02T18:57:52.837Z",
29-
"pages/docs/getting-started/assign-a-domain-name.js": "2018-05-11T13:40:09.706Z",
30-
"pages/docs/getting-started/deployment.js": "2018-05-11T13:40:09.706Z",
31-
"pages/docs/getting-started/environment-variables.js": "2018-05-11T13:40:09.707Z",
32-
"pages/docs/getting-started/five-minute-guide-to-now.js": "2018-05-11T13:40:09.707Z",
33-
"pages/docs/getting-started/index.js": "2018-05-02T18:57:52.838Z",
34-
"pages/docs/getting-started/logs.js": "2018-05-11T13:40:09.708Z",
35-
"pages/docs/getting-started/scaling.js": "2018-05-11T13:40:09.708Z",
36-
"pages/docs/getting-started/secrets.js": "2018-05-11T13:40:09.709Z",
37-
"pages/docs/getting-started/whats-next.js": "2018-05-11T13:40:09.709Z",
38-
"pages/docs/guides/app-lifecycle-and-scalability.js": "2018-05-11T13:40:09.710Z",
39-
"pages/docs/guides/how-to-use-cloudflare.js": "2018-05-11T13:40:09.711Z",
40-
"pages/docs/guides/index.js": "2018-05-02T18:57:52.839Z",
41-
"pages/docs/guides/migrate-your-app.js": "2018-05-11T13:40:09.711Z",
42-
"pages/docs/guides/redirect.js": "2018-05-11T13:40:09.712Z",
43-
"pages/docs/guides/updating-now-cli.js": "2018-05-11T13:40:09.712Z",
44-
"pages/docs/index.js": "2018-05-09T14:42:56.000Z",
45-
"pages/docs/other/billing.js": "2018-05-02T18:57:52.840Z",
46-
"pages/docs/other/faq.js": "2018-05-11T13:40:09.713Z",
47-
"pages/docs/other/index.js": "2018-05-02T18:57:52.841Z",
48-
"pages/docs/other/restrictions.js": "2018-05-11T13:40:09.713Z",
49-
"pages/docs/other/support-channels.js": "2018-05-11T13:40:09.714Z"
2+
"pages/docs/deployment-types/docker.js": "2018-05-20T11:02:28.927Z",
3+
"pages/docs/deployment-types/index.js": "2018-01-18T08:06:56.713Z",
4+
"pages/docs/deployment-types/lifecycle.js": "2018-01-18T08:06:56.713Z",
5+
"pages/docs/deployment-types/node.js": "2018-05-20T11:02:28.927Z",
6+
"pages/docs/deployment-types/static.js": "2018-05-20T11:02:28.927Z",
7+
"pages/docs/examples/chat.js": "2018-05-20T11:02:28.927Z",
8+
"pages/docs/examples/create-react-app.js": "2018-05-20T11:02:28.928Z",
9+
"pages/docs/examples/graphql.js": "2018-02-09T20:16:07.963Z",
10+
"pages/docs/examples/index.js": "2018-01-18T08:06:56.715Z",
11+
"pages/docs/examples/json-api.js": "2018-05-20T11:02:28.928Z",
12+
"pages/docs/examples/next.js": "2018-05-20T11:02:28.928Z",
13+
"pages/docs/examples/redirect.js": "2018-02-09T20:16:07.967Z",
14+
"pages/docs/examples/slack-slash.js": "2018-05-20T11:02:28.929Z",
15+
"pages/docs/examples/static.js": "2018-05-20T11:02:28.929Z",
16+
"pages/docs/examples/travis.js": "2018-05-20T11:02:28.930Z",
17+
"pages/docs/features/aliases.js": "2018-05-20T11:02:28.930Z",
18+
"pages/docs/features/certs.js": "2018-05-20T11:02:28.930Z",
19+
"pages/docs/features/configuration.js": "2018-05-20T11:02:28.931Z",
20+
"pages/docs/features/dns.js": "2018-05-20T11:02:28.931Z",
21+
"pages/docs/features/env-and-secrets.js": "2018-05-20T11:02:28.932Z",
22+
"pages/docs/features/index.js": "2018-01-18T08:06:56.719Z",
23+
"pages/docs/features/now-cli.js": "2018-05-20T11:02:28.932Z",
24+
"pages/docs/features/path-aliases.js": "2018-05-20T11:02:28.933Z",
25+
"pages/docs/features/private-npm.js": "2018-05-20T11:02:28.933Z",
26+
"pages/docs/features/repositories.js": "2018-05-20T11:02:28.934Z",
27+
"pages/docs/features/scaling.js": "2018-05-20T11:02:28.934Z",
28+
"pages/docs/features/zero-downtime-migration.js": "2018-01-18T08:06:56.720Z",
29+
"pages/docs/getting-started/assign-a-domain-name.js": "2018-05-20T11:02:28.934Z",
30+
"pages/docs/getting-started/deployment.js": "2018-05-20T11:38:57.000Z",
31+
"pages/docs/getting-started/environment-variables.js": "2018-05-20T11:02:28.935Z",
32+
"pages/docs/getting-started/five-minute-guide-to-now.js": "2018-05-20T11:02:28.936Z",
33+
"pages/docs/getting-started/index.js": "2018-01-18T08:06:56.722Z",
34+
"pages/docs/getting-started/logs.js": "2018-05-20T11:02:28.936Z",
35+
"pages/docs/getting-started/scaling.js": "2018-05-20T11:02:28.937Z",
36+
"pages/docs/getting-started/secrets.js": "2018-05-20T11:02:28.938Z",
37+
"pages/docs/getting-started/whats-next.js": "2018-05-20T11:02:28.939Z",
38+
"pages/docs/guides/app-lifecycle-and-scalability.js": "2018-05-20T11:02:28.941Z",
39+
"pages/docs/guides/how-to-use-cloudflare.js": "2018-05-20T11:02:28.942Z",
40+
"pages/docs/guides/index.js": "2018-01-18T08:06:56.726Z",
41+
"pages/docs/guides/migrate-your-app.js": "2018-05-20T11:02:28.943Z",
42+
"pages/docs/guides/redirect.js": "2018-05-20T11:02:28.943Z",
43+
"pages/docs/guides/updating-now-cli.js": "2018-05-20T11:02:28.944Z",
44+
"pages/docs/index.js": "2018-05-20T11:34:23.000Z",
45+
"pages/docs/other/billing.js": "2018-05-20T11:02:28.944Z",
46+
"pages/docs/other/faq.js": "2018-05-20T11:02:28.945Z",
47+
"pages/docs/other/index.js": "2018-01-18T08:06:56.727Z",
48+
"pages/docs/other/restrictions.js": "2018-05-20T11:02:28.945Z",
49+
"pages/docs/other/support-channels.js": "2018-05-20T11:02:28.946Z"
5050
}

Diff for: now.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2+
"type": "npm",
23
"alias": "docs.zeit.sh"
34
}

Diff for: package.json

+7-27
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,14 @@
33
"version": "5.8.2",
44
"private": true,
55
"scripts": {
6-
"dev": "node server.js",
6+
"dev": "micro server.js",
77
"build": "cross-env NODE_ENV=production next build",
8-
"export": "cross-env NODE_ENV=production next export",
9-
"start": "cross-env NODE_ENV=production node server.js",
8+
"start": "cross-env NODE_ENV=production micro server.js",
109
"lint": "eslint .",
1110
"lint:staged": "lint-staged",
1211
"test": "npm run lint",
13-
"deploy": "node scripts/deploy",
1412
"last:edited": "node scripts/last-edited && git add lib/data/last-edited.json"
1513
},
16-
"babel": {
17-
"presets": [
18-
"next/babel"
19-
],
20-
"plugins": [
21-
[
22-
"transform-define",
23-
"./env-config.js"
24-
],
25-
"markdown-in-js/babel"
26-
]
27-
},
2814
"dependencies": {
2915
"@skidding/react-codemirror": "1.0.2",
3016
"async-retry": "1.1.4",
@@ -44,15 +30,15 @@
4430
"js-cookie": "2.2.0",
4531
"jsonwebtoken": "7.4.1",
4632
"lodash.debounce": "4.0.8",
47-
"markdown-in-js": "1.1.3",
33+
"markdown-in-js": "1.1.4",
4834
"micro": "9.1.0",
4935
"mitt": "1.1.2",
50-
"next": "5.0.1-canary.3",
36+
"next": "6.0.3",
5137
"nprogress": "0.2.0",
5238
"prop-types": "15.5.8",
5339
"query-string": "4.3.4",
54-
"react": "16.1.1",
55-
"react-dom": "16.1.1",
40+
"react": "16.3.2",
41+
"react-dom": "16.3.2",
5642
"scroll-into-view-if-needed": "1.1.0",
5743
"smoothscroll-polyfill": "0.3.5"
5844
},
@@ -63,8 +49,7 @@
6349
"eslint-plugin-react": "7.1.0",
6450
"lint-staged": "4.0.0",
6551
"pre-commit": "1.2.2",
66-
"prettier": "1.7.4",
67-
"shelljs": "0.7.8"
52+
"prettier": "1.7.4"
6853
},
6954
"lint-staged": {
7055
"*.js": [
@@ -77,11 +62,6 @@
7762
"last:edited",
7863
"lint:staged"
7964
],
80-
"greenkeeper": {
81-
"ignore": [
82-
"prettier"
83-
]
84-
},
8565
"eslintConfig": {
8666
"parser": "babel-eslint",
8767
"parserOptions": {

Diff for: scripts/deploy.js

-50
This file was deleted.

Diff for: server.js

+29-32
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
const micro = require('micro')
21
const next = require('next')
32
const qs = require('querystring')
43
const url = require('url')
54

65
const dev = process.env.NODE_ENV !== 'production'
7-
const dir = __dirname
8-
const port = process.env.PORT || 5800
96

10-
const logger = console
11-
const app = next({ dev, dir })
12-
const handleNextRequests = app.getRequestHandler()
7+
const app = next({ dev })
8+
const handle = app.getRequestHandler()
139

1410
function removeEndSlash(fn) {
1511
return (req, res) => {
@@ -30,32 +26,33 @@ function removeEndSlash(fn) {
3026
}
3127
}
3228

33-
app.prepare().then(() => {
34-
const server = micro(
35-
removeEndSlash((req, res, parsedUrl) => {
36-
// Add assetPrefix support based on the hostname
37-
if (req.headers.host === 'docs.zeit.sh') {
38-
// Set the cloudinary custom origin which points to https://docs.zeit.sh
39-
app.setAssetPrefix('https://assets.zeit.co/raw/upload/docs-assets')
40-
} else if (/localhost/.test(req.headers.host)) {
41-
// Set the assetPrefix for localhost
42-
// It needs to be the http version
43-
app.setAssetPrefix(`http://${req.headers.host}`)
44-
} else {
45-
// Set the assetPrefix for now
46-
// It needs to be the https version, since now is always HTTPS
47-
app.setAssetPrefix(`https://${req.headers.host}`)
48-
}
49-
50-
handleNextRequests(req, res, parsedUrl)
29+
async function main(req, res, parsedUrl) {
30+
if (req.url === '/') {
31+
res.writeHead(301, {
32+
Location: '/docs'
5133
})
52-
)
34+
res.end()
35+
return
36+
}
37+
if (req.headers.host === 'docs.zeit.sh') {
38+
// Set the cloudinary custom origin which points to https://docs.zeit.sh
39+
app.setAssetPrefix('https://assets.zeit.co/raw/upload/docs-assets')
40+
} else if (/localhost/.test(req.headers.host)) {
41+
// Set the assetPrefix for localhost
42+
// It needs to be the http version
43+
app.setAssetPrefix(`http://${req.headers.host}`)
44+
} else {
45+
// Set the assetPrefix for now
46+
// It needs to be the https version, since now is always HTTPS
47+
app.setAssetPrefix(`https://${req.headers.host}`)
48+
}
5349

54-
server.listen(port, err => {
55-
if (err) {
56-
throw err
57-
}
50+
handle(req, res, parsedUrl)
51+
}
52+
53+
async function setup(handler) {
54+
await app.prepare()
55+
return removeEndSlash(handler)
56+
}
5857

59-
logger.log(`> Ready on http://localhost:${port}`)
60-
})
61-
})
58+
module.exports = setup(main)

0 commit comments

Comments
 (0)