|
| 1 | +import fetch from 'node-fetch' |
1 | 2 | import { describe, expect, test } from 'vitest'
|
2 | 3 |
|
| 4 | +import { withDevServer } from '../../utils/dev-server.js' |
3 | 5 | import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js'
|
4 |
| -import fetch from 'node-fetch' |
| 6 | +import { withSiteBuilder } from '../../utils/site-builder.js' |
5 | 7 |
|
6 | 8 | describe('redirects', () => {
|
7 | 9 | setupFixtureTests('dev-server-with-functions', { devServer: true }, () => {
|
@@ -50,4 +52,58 @@ describe('redirects', () => {
|
50 | 52 | expect(result.toLowerCase()).not.toContain('netlify')
|
51 | 53 | })
|
52 | 54 | })
|
| 55 | + |
| 56 | + test('should not check the endpoint existence for hidden proxies', async (t) => { |
| 57 | + await withSiteBuilder(t, async (builder) => { |
| 58 | + await builder |
| 59 | + .withContentFile({ |
| 60 | + path: './index.js', |
| 61 | + content: ` |
| 62 | + const http = require('http') |
| 63 | + const server = http.createServer((req, res) => { |
| 64 | + console.log('Got request main server', req.method, req.url) |
| 65 | + res.end() |
| 66 | + }) |
| 67 | + server.listen(6125) |
| 68 | +
|
| 69 | + const proxyServer = http.createServer((req, res) => { |
| 70 | + console.log('Got request proxy server', req.method, req.url) |
| 71 | + res.end() |
| 72 | + }) |
| 73 | + proxyServer.listen(6126) |
| 74 | + `, |
| 75 | + }) |
| 76 | + .withNetlifyToml({ |
| 77 | + config: { |
| 78 | + dev: { |
| 79 | + targetPort: 6125, |
| 80 | + command: 'node index.js', |
| 81 | + }, |
| 82 | + redirects: [ |
| 83 | + { |
| 84 | + from: '/from-hidden', |
| 85 | + to: 'http://localhost:6126/to', |
| 86 | + status: 200, |
| 87 | + headers: { 'x-nf-hidden-proxy': 'true' }, |
| 88 | + }, |
| 89 | + { from: '/from', to: 'http://localhost:6126/to', status: 200 }, |
| 90 | + ], |
| 91 | + }, |
| 92 | + }) |
| 93 | + .build() |
| 94 | + |
| 95 | + await withDevServer( |
| 96 | + { cwd: builder.directory, env: { NETLIFY_DEV_SERVER_CHECK_SSG_ENDPOINTS: '1' } }, |
| 97 | + async ({ outputBuffer, url }) => { |
| 98 | + await fetch(new URL('/from-hidden', url)) |
| 99 | + t.expect(String(outputBuffer)).not.toContain('Got request main server') |
| 100 | + t.expect(String(outputBuffer)).toContain('Got request proxy server GET /to') |
| 101 | + await fetch(new URL('/from', url)) |
| 102 | + t.expect(String(outputBuffer.join(''))).toContain( |
| 103 | + 'Got request main server HEAD /from\nGot request main server GET /from', |
| 104 | + ) |
| 105 | + }, |
| 106 | + ) |
| 107 | + }) |
| 108 | + }) |
53 | 109 | })
|
0 commit comments