Flask middleware for specific route

There are a few ways how to add custom processing before specific endpoint. 1) Using python decorator: from functools import wraps def home_decorator(): def _home_decorator(f): @wraps(f) def __home_decorator(*args, **kwargs): # just do here everything what you need print(‘before home’) result = f(*args, **kwargs) print(‘home result: %s’ % result) print(‘after home’) return result return __home_decorator return … Read more

NodeJS Express – separate routes on two ports

Based on Explosion Pills suggestion above, I modified the code in roughly this way: var express = require(‘express’); var things = []; var app = express(); var admin_app = express(); var port = 8080; var admin_port = 8081; app.post(‘/factory/’, function(req, res) { //Create a thing and add it to the thing array }); //Assume more … Read more

How to serve index.html with web api selfhosted with OWIN

Move your Index.html to the root of your project. Then install-package Microsoft.Owin.StaticFiles in Package Manager Console and add the code below: public class Startup { public void Configuration(IAppBuilder app) { const string rootFolder = “.”; var fileSystem=new PhysicalFileSystem(rootFolder); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = fileSystem }; app.UseFileServer(options); } } This … Read more

Adding ID and title to URL slugs in ASP.NET MVC

First create a route: routes.MapRoute( “ViewProduct”, “Products/{id}/{productName}”, new { controller = “Product”, action = “Details”, id = “”, productName = “” } ); Then create the Action method like so: public ActionResult Details(int? id, string productName) { Product product = ProductRepository.Fetch(id); string realTitle = UrlEncoder.ToFriendlyUrl(product.Title); string urlTitle = (productName ?? “”).Trim().ToLower(); if (realTitle != urlTitle) … Read more

Route to static file in Play! 2.0

IIRC, change <link rel=”stylesheet” media=”screen” href=”https://stackoverflow.com/questions/9792875/@routes.Assets.at(“stylesheets/main.css”)”> To <link rel=”stylesheet” media=”screen” href=”https://stackoverflow.com/questions/9792875/@routes.Assets.at(“stylesheets/”, “main.css”)”> I am talking about your third attempt Also, watch out for extra / EDIT GET /assets/main.css controllers.Assets.at(path=”/public”, file=”/stylesheets/main.css”) Assuming your resource is at /public/stylesheets/main.css

tech