diff --git a/examples/with-custom-reverse-proxy/.babelrc b/examples/with-custom-reverse-proxy/.babelrc index 689c9339..d4472470 100644 --- a/examples/with-custom-reverse-proxy/.babelrc +++ b/examples/with-custom-reverse-proxy/.babelrc @@ -1,7 +1,5 @@ { "presets": [ - "next/babel", - "latest", - "stage-0" + "next/babel" ] } diff --git a/examples/with-custom-reverse-proxy/package.json b/examples/with-custom-reverse-proxy/package.json index f6b846c4..44316822 100644 --- a/examples/with-custom-reverse-proxy/package.json +++ b/examples/with-custom-reverse-proxy/package.json @@ -8,9 +8,6 @@ "react-dom": "16.2.0" }, "devDependencies": { - "babel-preset-latest": "^6.24.1", - "babel-preset-stage-0": "^6.24.1", - "babel-register": "^6.24.1", "cross-env": "^5.0.1", "http-proxy-middleware": "^0.17.4" }, diff --git a/examples/with-custom-reverse-proxy/server.es6.js b/examples/with-custom-reverse-proxy/server.es6.js deleted file mode 100644 index 6f1ada56..00000000 --- a/examples/with-custom-reverse-proxy/server.es6.js +++ /dev/null @@ -1,50 +0,0 @@ -/* eslint-disable no-console */ -import express from 'express' -import next from 'next' - -const devProxy = { - '/api': { - target: 'https://swapi.co/api/', - pathRewrite: {'^/api': '/'}, - changeOrigin: true - } -} - -const port = parseInt(process.env.PORT, 10) || 3000 -const env = process.env.NODE_ENV -const dev = env !== 'production' -const app = next({ - dir: '.', // base directory where everything is, could move to src later - dev -}) - -const handle = app.getRequestHandler() - -let server -app - .prepare() - .then(() => { - server = express() - - // Set up the proxy. - if (dev && devProxy) { - const proxyMiddleware = require('http-proxy-middleware') - Object.keys(devProxy).forEach(function (context) { - server.use(proxyMiddleware(context, devProxy[context])) - }) - } - - // Default catch-all handler to allow Next.js to handle all other routes - server.all('*', (req, res) => handle(req, res)) - - server.listen(port, err => { - if (err) { - throw err - } - console.log(`> Ready on port ${port} [${env}]`) - }) - }) - .catch(err => { - console.log('An error occurred, unable to start the server') - console.log(err) - }) diff --git a/examples/with-custom-reverse-proxy/server.js b/examples/with-custom-reverse-proxy/server.js index 594c6a8e..9620a4e4 100644 --- a/examples/with-custom-reverse-proxy/server.js +++ b/examples/with-custom-reverse-proxy/server.js @@ -1,2 +1,50 @@ -require('babel-register') -module.exports = require('./server.es6.js') +/* eslint-disable no-console */ +const express = require('express') +const next = require('next') + +const devProxy = { + '/api': { + target: 'https://swapi.co/api/', + pathRewrite: {'^/api': '/'}, + changeOrigin: true + } +} + +const port = parseInt(process.env.PORT, 10) || 3000 +const env = process.env.NODE_ENV +const dev = env !== 'production' +const app = next({ + dir: '.', // base directory where everything is, could move to src later + dev +}) + +const handle = app.getRequestHandler() + +let server +app + .prepare() + .then(() => { + server = express() + + // Set up the proxy. + if (dev && devProxy) { + const proxyMiddleware = require('http-proxy-middleware') + Object.keys(devProxy).forEach(function (context) { + server.use(proxyMiddleware(context, devProxy[context])) + }) + } + + // Default catch-all handler to allow Next.js to handle all other routes + server.all('*', (req, res) => handle(req, res)) + + server.listen(port, err => { + if (err) { + throw err + } + console.log(`> Ready on port ${port} [${env}]`) + }) + }) + .catch(err => { + console.log('An error occurred, unable to start the server') + console.log(err) + })