perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.63k stars 1.56k forks source link

Proxy Server; or Forward & mask requests #994

Open abhinavsayan opened 6 years ago

abhinavsayan commented 6 years ago

I am trying to create a proxy server using spark.

This is purely for development purpose. Fox example during development of an angular app I would like to proxy the static resources to the angular instance that is running on say port 4200. While my spark app continues to run on the default port.

This will allow me to serve the static content by avoiding problems such as session and CROS while still being able to take advantage of webpack.

Could anybody offer any suggestions or alternatives. Thinking of something on the following front :

port(80);
// define api routes here
// if no match then forward to proxy
get("/*", (req, res) -> {
    // forward (not redirect) the requests to localhost 4200
});
post("/*", (req, res) -> {
    // forward (not redirect) the requests to localhost 4200
});

// also consider sockets