Skip to content

Commit

Permalink
fix: add hint for "universal" mode only (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlexLichter authored and pi0 committed Oct 30, 2018
1 parent 555af39 commit c78b122
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

✓ ...and more! (see [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware) docs)

⚠ Does not work in generated/static mode!

## Setup
- Add `@nuxtjs/proxy` dependency using yarn or npm to your project
- Add `@nuxtjs/proxy` to `modules` section of `nuxt.config.js`
Expand Down
4 changes: 4 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ module.exports = function nuxtProxy (options) {
return
}

this.nuxt.hook('generate:before', () => {
consola.warn('This module does not work in generated mode')
})

// Defaults
const defaults = Object.assign(
{
Expand Down
43 changes: 41 additions & 2 deletions test/module.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
const { Nuxt } = require('nuxt-edge')
const request = require('request-promise-native')
const { Nuxt, Generator, Builder } = require('nuxt-edge')
const consola = require('consola')

const request = require('request-promise-native')
const config = require('./fixture/nuxt.config')

const url = path => `http://localhost:3000${path}`
const get = path => request(url(path))

describe('warnings', () => {
let nuxt
let log

beforeEach(() => {
log = jest.fn()
consola.clear().add({ log })
})

afterEach(async () => {
await nuxt.close()
})

it('generate', async () => {
nuxt = new Nuxt(
Object.assign({}, config, {
render: {
ssr: false
},
proxy: {
'/proxy': url('/api'),
'/rewrite': {
target: url('/api'),
pathRewrite: { '^/rewrite': '' }
}
}
})
)
const generator = new Generator(nuxt, new Builder(nuxt))
await generator.initiate()
await generator.initRoutes()

const messageInExtendFunction = 'This module does not work in generated mode'
const consolaMessages = log.mock.calls.map(c => c[0].message)
expect(consolaMessages).toContain(messageInExtendFunction)
}, 30000)
})

describe('object mode', () => {
let nuxt

Expand Down

0 comments on commit c78b122

Please sign in to comment.