Skip to content

Commit

Permalink
Now serverless ready
Browse files Browse the repository at this point in the history
  • Loading branch information
raulg committed Mar 28, 2019
2 parents 0c7784b + e40524d commit ec9e73b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 64 deletions.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@ You can use our [Prismic-CLI](https://github.com/prismicio/prismic-cli) tool to
```
> $ npm install
```
### Runs the app in the development mode
Build and open your browser to http:https://localhost:3000.
```
> $ npm run dev
```

### Builds the app for production using Next.js
```
> $ npm run build
```

### Deploy to Now 2.0 serverless mode
[Install Now](https://zeit.co/download) and register in the Now platform for deploying your site using serverless features. The required routing and setup files are already included in the project. Just run the `now` command in your project folder.
```
> $ now
```

### Run serverless mode locally
_This is still in development_ As of version 14.3.0-canary.21 of `now-cli` you can use the `now dev` command to run the project in your local machine. You can use this to set up and test your routing in `now.json` without having to deploy to Now for every small change.
```
> $ now dev
```
Do a hard refresh (Command + Shift + R in OSX) in your browser after making any changes to trigger a local rebuild.

### Get started with Prismic

You can find out how to get started with Prismic from [our React documentation](https://prismic.io/docs/reactjs/getting-started/getting-started-from-scratch).
Expand Down
10 changes: 10 additions & 0 deletions now.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 2,
"name": "prismic-nextjs-blog",
"builds": [{ "src": "next.config.js", "use": "@now/next" }],
"routes": [
{ "src": "/preview\\?(?<query>.*)", "dest": "/preview?query=$query" },
{ "src": "/blog/?", "status": 302, "headers": { "Location": "/" } },
{ "src": "/blog/(?<uid>[^/]+)$", "dest": "/post?uid=$uid" }
]
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"email": "[email protected]"
},
"dependencies": {
"express": "^4.16.4",
"next": "^8.0.3",
"prismic-javascript": "^2.0.3",
"prismic-reactjs": "^0.3.2",
Expand All @@ -19,7 +18,7 @@
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
"now-build": "next build"
},
"repository": {
"type": "git",
Expand Down
13 changes: 3 additions & 10 deletions pages/preview.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import Prismic from 'prismic-javascript';
import Router from 'next/router';
import { apiEndpoint, linkResolver } from '../prismic-configuration';
import { apiEndpoint, linkResolver } from 'prismic-configuration';

export default class Preview extends React.Component {
static async getInitialProps(context) {
Expand All @@ -11,14 +10,8 @@ export default class Preview extends React.Component {
const API = await Prismic.getApi(apiEndpoint, {req});
const url = await API.previewSession(token, linkResolver, '/');

if (res) {
res.writeHead(302, {
Location: url
})
res.end()
} else {
Router.push(url)
}
res.writeHead(302, { Location: url });
res.end();
return {}
}

Expand Down
45 changes: 0 additions & 45 deletions server.js

This file was deleted.

0 comments on commit ec9e73b

Please sign in to comment.