import {HTTP} from "@gongt/ts-stl-library/request/request";
import {Response} from "express-serve-static-core";
import * as React from "react";
import {RenderContext} from "../middlewares/html-render";

export function routerStatus(context: RenderContext, response: Response) {
	const router_context = context.global.get('sr_router_context');
	
	if (router_context.status) {
		response.status(HTTP.OK);
	}
	
	if (router_context.url) {
		// Somewhere a `<Redirect>` was rendered
		if (!router_context.status) {
			response.status(HTTP.FOUND);
		}
		response.header('location', router_context.url);
		response.end();
		return true;
	}
}

