TypeScript support for setupProxy
Created by: dannycochran
I understand the docs specifically call out that the setupProxy
file does not support additional languages. However, without TypeScript support, the setupProxy
file cannot import other TypeScript code from within src
.
My use case:
// src/setupProxy.js
//
// @ts-ignore: isolated modules error
const proxy = require('http-proxy-middleware');
const backends = require('./common/backends');
const addressInfo = backends.getServerAddress();
module.exports = function (app) {
app.use(proxy([
backends.apiRoot,
backends.graphqlRoot,
backends.mediaRoot,
], { target: `http://${addressInfo.host}:${addressInfo.port}/` }));
};
This will result in an error, Cannot find module './common/backends'
, which makes sense because ./common/backends
is a TypeScript file. However, I would be able to require this file if my project were JavaScript.
Without this, I'll have to duplicate the addressInfo
and path locations from backends
in setupProxy
.