diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfe0770..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/README.md b/README.md index 9e3f1a2..cd9b755 100644 --- a/README.md +++ b/README.md @@ -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://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). diff --git a/now.json b/now.json new file mode 100644 index 0000000..5ec40a5 --- /dev/null +++ b/now.json @@ -0,0 +1,10 @@ +{ + "version": 2, + "name": "prismic-nextjs-blog", + "builds": [{ "src": "next.config.js", "use": "@now/next" }], + "routes": [ + { "src": "/preview\\?(?.*)", "dest": "/preview?query=$query" }, + { "src": "/blog/?", "status": 302, "headers": { "Location": "/" } }, + { "src": "/blog/(?[^/]+)$", "dest": "/post?uid=$uid" } + ] +} \ No newline at end of file diff --git a/package.json b/package.json index d0e43c6..a1f3f83 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ "email": "raul.gonzalez@prismic.io" }, "dependencies": { - "express": "^4.16.4", "next": "^8.0.3", "prismic-javascript": "^2.0.3", "prismic-reactjs": "^0.3.2", @@ -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", diff --git a/pages/preview.js b/pages/preview.js index 1e5dc83..d140c9a 100644 --- a/pages/preview.js +++ b/pages/preview.js @@ -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) { @@ -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 {} } diff --git a/server.js b/server.js deleted file mode 100644 index 533fcb1..0000000 --- a/server.js +++ /dev/null @@ -1,45 +0,0 @@ -const express = require('express'); -const dev = process.env.NODE_ENV !== 'production'; -const next = require('next'); -const app = next({ dev }); -const handle = app.getRequestHandler(); - -const Prismic = require('prismic-javascript'); -const { apiEndpoint, linkResolver } = require('./prismic-configuration'); - -app - .prepare() - .then(() => { - const server = express(); - - server.get('/preview', (req, res) => { - const token = req.query.token; - - Prismic.getApi(apiEndpoint, {req}) - .then((api) => api.previewSession(token, linkResolver, '/')) - .then((url) => { - res.redirect(302, url); - }); - }); - - server.get('/blog/:uid', (req, res) => { - const nextJsPage = '/post'; - const queryParams = { uid: req.params.uid }; - app.render(req, res, nextJsPage, queryParams); - }); - - server.get('/blog', (req, res) => { - res.redirect(302, '/'); - }); - - server.get('*', (req, res) => handle(req, res)); - - server.listen(3000, err => { - if (err) throw err; - console.log('> Ready http://localhost:3000 <'); - }); - }) - .catch(ex => { - console.error(ex.stack); - process.exit(1); - }); \ No newline at end of file