pearofducks / rollup-plugin-dev

development server for rollup with additional logging and options
MIT License
61 stars 9 forks source link

proxy not working #11

Closed sysmat closed 3 years ago

sysmat commented 3 years ago
import dev from 'rollup-plugin-dev'

dev({
    dirs: ['public'],
    port: 5000,
    host: 'localhost',
    proxy: {
        '/api/*': 'http://localhost:8080/analizator'
    }
})

None of API calls work

[2021-05-08 13:40:43] waiting for changes...
⚡︎dev-server listening on http://127.0.0.1:5000
[2021-05-08 13:40:47] GET / • 200 12ms
[2021-05-08 13:40:47] GET /build/bundle.css • 200 2ms
[2021-05-08 13:40:47] GET /build/bundle.js • 200 2ms
[2021-05-08 13:40:48] GET /api/version • 404 19ms
[2021-05-08 13:40:48] GET /api/queries/ • 404 5ms
[2021-05-08 13:44:07] GET /api/ciscoStatus • 404 12ms
[2021-05-08 13:44:07] GET /api/ciscoStatus • 404 8ms
[2021-05-08 13:44:10] GET /api/queries/ • 404 4ms
[2021-05-08 13:49:08] GET /api/ciscoStatus • 404 4ms
pearofducks commented 3 years ago

Hi! There's a test specifically for proxies that's passing fine, this is likely something to do with your configuration/setup, but issues are not the place to debug those.

If you still feel this is a valid problem with proxies, you can submit a minimal reproduction.

sysmat commented 3 years ago
import svelte from 'rollup-plugin-svelte';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import serveLocal from 'rollup-plugin-serve'

import sveltePreprocess from 'svelte-preprocess';
import typescript from '@rollup/plugin-typescript';
import css from 'rollup-plugin-css-only';
import dev from 'rollup-plugin-dev'
import replace from '@rollup/plugin-replace'

const production = !process.env.ROLLUP_WATCH;
console.log('production', production);

function serve() {
    let server;

    function toExit() {
        if (server) server.kill(0);
    }

    return {
        writeBundle() {
            if (server) return;
            server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
                stdio: ['ignore', 'inherit', 'inherit'],
                shell: true
            });

            process.on('SIGTERM', toExit);
            process.on('exit', toExit);
        }
    };
}

export default {
    input: 'src/main.ts',
    output: {
        sourcemap: true,
        format: 'iife',
        name: 'app',
        file: 'public/build/bundle.js'
    },
    plugins: [
        replace({
            'process.env.NODE_ENV': JSON.stringify('production')
        }),
        svelte({
            preprocess: sveltePreprocess({ sourceMap: !production }),
            compilerOptions: {
                // enable run-time checks when not in production
                dev: !production
            }
        }),
        // we'll extract any component CSS out into
        // a separate file - better for performance
        css({ output: 'bundle.css' }),

        // If you have external dependencies installed from
        // npm, you'll most likely need these plugins. In
        // some cases you'll need additional configuration -
        // consult the documentation for details:
        // https://github.com/rollup/plugins/tree/master/packages/commonjs
        resolve({
            browser: true,
            dedupe: ['svelte']
        }),
        commonjs(),
        typescript({
            sourceMap: !production,
            inlineSources: !production
        }),
        !production && livereload('public'),
        production && terser(),
        dev({
            dirs: ['public'],
            port: 5000,
            host: 'localhost',
            proxy: {
                '/api/*': 'http://localhost:8080/analizator'
            }
        })

    ],
    watch: {
        clearScreen: false
    }
};

test specifically for proxies

what do you mean by that?

pearofducks commented 3 years ago

Pasting your Rollup config is not a minimum reproduction. The readme has both an example and a link to further documentation on proxies. I'm closing this as invalid.

sysmat commented 3 years ago

Ok I'm reverting it to webpack it is working proxy, non of proxy solution's for rollup seams to work in my case. So the same project is working dev proxy with angular, webpack in dev environment

sysmat commented 3 years ago
const devServer = dev({
    dirs: ['public'],
    port: 5000,
    host: 'localhost',
    proxy: {
        '/api*': ['http://localhost:9090/analizator', {
            https: false, filter: (ctx) => {
                console.log('ctx', ctx);
                return ctx.method === 'GET';
            }
        }]
    }
});
 {
  request: {
    method: 'GET',
    url: '/api/queries/',
    header: {
      host: '127.0.0.1:5000',
      connection: 'keep-alive',
      'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
      'sec-ch-ua-mobile': '?0',
      'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
      accept: '*/*',
      'sec-fetch-site': 'same-origin',
      'sec-fetch-mode': 'cors',
      'sec-fetch-dest': 'empty',
      referer: 'http://127.0.0.1:5000/',
      'accept-encoding': 'gzip, deflate, br',
      'accept-language': 'en-US,en;q=0.9'
    }
  },
  response: {
    status: 404,
    message: 'Not Found',
    header: [Object: null prototype] {}
  },
  app: { subdomainOffset: 2, proxy: false, env: 'development' },
  originalUrl: '/api/queries/',
  req: '<original node req>',
  res: '<original node res>',
  socket: '<original node socket>'
}
/api/queries/ --proxy--> http://localhost:9090/api/queries/ // this is wrong

// it should send to 
/api/queries/ --proxy--> http://localhost:9090/analizator/api/queries/ 

Most of the proxy's I know from other languages work as mapping 'path1' -> ${baseSecondUri}/path1

sysmat commented 3 years ago

I se this lib use koa-better-http-proxy, so bug is in koa-better-http-proxy or this lib not passing proxy args well to koa