2

I cloned an angular2-webpack-starter project and it works well; now I want to add a separate NodeJS server to this project(I need to mock some data with NodeJS for back-end), but don't know how and where to start, can someone help?

0

1 Answer 1

1

This issue was resolved, just need to config proxy of devServer in config/webpack.dev.js:

module.exports = {
  entry:{...},
  ...
  devServer: {
        host: 'localhost',
        port: 8086, //frontend port
        historyApiFallback: true,
        noInfo: true,
        watchOptions: {
            aggregateTimeout: 300,
            poll: 100
        },
        outputPath: '/',
        proxy: {
            '/api/*': { //backend url prefix, some thing like '/api/users/:userId'
                target: 'http://localhost:3000', // backend host and port
                secure: false
            }
        }
    }
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.