Starcounter
HomeDownloadDocsCommunity
2.3.2
2.3.2
  • Starcounter Documentation
  • Getting Started
  • Starcounter
    • Collapsing the Stack
      • Complexity and Scalability Tradeoff
      • The Future of Micro-Services
      • 10 Benefits of Collapsing the Stack
    • Integrated Database and Web Server
  • Hello World - Tutorial
    • Create a Database Class
    • Create a Real Time UI
    • First Interactive UI
    • Computed Properties
    • Expense Tracker
    • Cancel and Delete
    • The Next Step
  • Guides
    • Database
      • Database Classes
      • Data manipulation
      • Object Identity and Object References
      • Querying with SQL
      • Data Types
      • Relations
      • Inheritance
      • Sharing data
      • Database Configuration
      • Comparing Database Objects
      • Referential Integrity and Constraints
    • SQL
      • Identifiers
      • Path Expressions
      • Data operators
      • Joins
      • Aggregates
      • Comparisons and Logical Operators
      • Sorting
      • Fetch
      • Offset Key
      • Indexes
      • Literals
      • Query Plan Hints
      • Reserved words
      • Query for Database Classes
      • SQL Isolation Between Applications
    • Transactions
      • Short-Running Transactions
      • Long running transactions
      • Using Transactions
      • Running Background Jobs
      • Commit Hooks
      • Post-commit hooks
    • Typed JSON
      • JSON-by-example
      • Code-Behind
      • Data Bindings
      • Callback Methods
      • Responding with JSON
      • Accepting JSON in Requests
      • Primitive Arrays and Single Value Types
      • Typed JSON Internals
    • Blendable Web Apps
      • Starcounter MVVM
      • Palindrom
      • Client-Side Stack
      • Sessions
      • HTML Views
      • App Shell
      • Web Components
      • View Attaching
      • View Composing
      • HTML Compositions
      • HTML Views Blending Guidelines
      • Avoiding CSS conflicts
      • Debugging
    • Network
      • HTTP
      • Internal Self Calls
      • Middleware
      • Anonymous or Substitute Handlers
      • URL Aliases and Redirects
      • Network Gateway
      • Static File Server
      • WebSocket
      • Avoiding URI conflicts
      • TCP Sockets
      • UDP Sockets
    • Publishing Apps
    • Working with Starcounter
      • Release Channels
      • Installation
      • Starting and Stopping Apps
      • Administrator Web UI
      • Star CLI
      • StarAdmin CLI
      • StarDump CLI
      • Working in Visual Studio
      • Error Log
      • Using HTTPS on NGINX
      • Using HTTPS on IIS
      • Run Starcounter in Production
      • Weaver
      • Investigating App Crashes
      • Configuration Structure
      • Database Refactoring
      • Using Unload/Reload to Modify Database Schema
      • Kernel Questions and Answers
      • Log Files
  • Cookbook
    • Attach an HTTP Request to an Existing Long-Running Transaction
    • Cookie-Based Authentication
    • Timestamp on Object Creation
    • Creating Strongly Typed JSON Collections
    • Migrating From 2.2 to 2.3+
    • Multiple Pages
    • Icons
    • Proposed Project Structure
    • Acceptance Testing with Selenium
    • Requesting a User to Authenticate
    • How to delete unused tables and columns
Powered by GitBook
On this page
  • Introduction
  • Alias
  • Redirect
  • API for Redirection
  • Uri Aliasing
  • URI Aliasing in Network Gateway
  • API for URI Aliasing
  1. Guides
  2. Network

URL Aliases and Redirects

Introduction

With HTTP handlers, it is possible to express URL transformations such as aliases and redirects.

Alias

An alias is a GET handle that returns the result of an Self.GET call.

For web apps, the URL displayed in the browser address bar does not get changed to the destination value.

Example:

Handle.GET("/pmail", () =>
{
  return Self.GET("/pmail/inbox");
});

Starcounter gateway has support for aliases which is described in Network Gateway section.

Redirect

An HTTP redirect is a server response that guides the client to access the resource using a different URL. It is achieved by an appropriate HTTP status code and value of the Location header.

For web apps, the URL displayed in the browser address bar gets changed to the destination value.

Example:

Handle.GET("/villains/anakin-skywalker", () =>
{
  var resp = new Response()
  {
    StatusCode = 302,
    StatusDescription = "Moved Permanently"
  };
  resp.Headers["Location"] = "/villains/darth-vader";
  return resp;
});

API for Redirection

To redirect your app's URL handler to another handler, call GET /sc/redirect/{PortNumber}{FromUri};{ToUri} on system port (by default 8181).

For example, to create redirection of / to /myapp on port 8080, the following handler should be called: GET /sc/redirect/8080/;/myapp on system port (by default 8181).

To create redirection on the startup of your application, you may call Http.GET(8181, "/sc/redirect/8080/;/myapp");. Keep in mind, that any other app can overwrite this redirect because there can only be one app handling the host root.

Uri Aliasing

URI Aliasing in Network Gateway

The classical example is to alias root URI to some other URI in your application. URI aliases are configured in scnetworkgateway.xml in your server directory. The following section is an excerpt from gateway configuration:

<UriAliases>
    <UriAlias>
        <HttpMethod>GET</HttpMethod>
        <FromUri>/</FromUri>
        <ToUri>/index.html</ToUri>
        <Port>8181</Port>
    </UriAlias>

    <UriAlias>
        <HttpMethod>GET</HttpMethod>
        <FromUri>/</FromUri>
        <ToUri>/launcher</ToUri>
        <Port>8080</Port>
    </UriAlias>
</UriAliases>
  • HttpMethod: for which HTTP method the alias is created.

  • FromUri: URI that should be aliased.

  • ToUri: URI to which the aliased URI should be changed.

  • Port: port on which this rule should apply.

In the example above we have declared two URI aliases: 1. On port 8181 from URI "/" to "/index.html". This is often used to display application initial "index" page when user just specifies the DNS name of the Web-server in the browser. 2. On port 8080 from URI "/" to "/launcher". Used to display a dynamic launcher page for the same purposes.

API for URI Aliasing

Starcounter allows adding, modifying, listing, and deleting URI aliases using the following REST API (should be called on system port (by default 8181)):

  • Adding and modifying a specific URI alias is done using PUT /sc/alias. The URI alias info should be in HTTP body with the following format:

{
  "HttpMethod": "",
  "FromUri": "",
  "ToUri": "",
  "Port": 0
}

for example, {"HttpMethod":"GET","FromUri":"/","ToUri":"/launcher","Port":8080}

  • Listing all URI aliases is done using GET /sc/alias:

{  
  "Items":[  
    {  
      "HttpMethod": "GET",
      "FromUri": "/",
      "ToUri": "/launcher",
      "Port": 8080
    },
    {  
      "HttpMethod": "GET",
      "FromUri": "/myapp",
      "ToUri": "/myappalias",
      "Port": 8080
    }
  ]
}

Retrieving info about specific URI alias is done using GET /sc/alias/{?}/{?}/{?} where parameters are string httpMethod, long dbport, string fromUri. For example, http://127.0.0.1:8181/sc/alias/GET/8080//SomeFromUri

Deleting specific URI alias is done using DELETE /sc/alias/{?}/{?}/{?} where parameters are string httpMethod, long dbport, string fromUri. For example, http://127.0.0.1:8181/sc/alias/GET/8080//SomeFromUri

In comparison with redirects, URI aliasing API adds entries to network gateway configuration and preserved upon gateway/code-host restart.

PreviousAnonymous or Substitute HandlersNextNetwork Gateway

Last updated 7 years ago