ASP.NET 6.0 SPA에서 Web API 끝점을 setupProxy 파일에 추가
ASP.NET 6.0 SPA에서 Web API 끝점을 setupProxy 파일에 추가
ASP.NET Core 6.0과 React.js를 함께 사용하는 SPA 템플릿에서 Web API를 하나 만들었다면,
이 정보를 반드시 setupProxy.js 파일의 context에 넣어주어야 합니다.
const createProxyMiddleware = require('http-proxy-middleware');
const { env } = require('process');
const target = env.ASPNETCORE_HTTPS_PORT ? `https://localhost:${env.ASPNETCORE_HTTPS_PORT}` :
    env.ASPNETCORE_URLS ? env.ASPNETCORE_URLS.split(';')[0] : 'http://localhost:32854';
const context = [
    "/weatherforecast",
    "/_configuration",
    "/.well-known",
    "/Identity",
    "/connect",
    "/ApplyDatabaseMigrations",
    "/_framework",
    "/api/Entries", // 추가
    "/api/Books" // 추가 
];
module.exports = function (app) {
    const appProxy = createProxyMiddleware(context, {
        target: target,
        secure: false
    });
    app.use(appProxy);
};
Comments
Comments are closed