Using node.js as a simple web server

后端 未结 30 2198
感情败类
感情败类 2020-11-22 02:54

I want to run a very simple HTTP server. Every GET request to example.com should get index.html served to it but as a regular HTML page (i.e., same

30条回答
  •  梦如初夏
    2020-11-22 03:10

    I can also recommend SugoiJS, it is very easy to set up and gives an option to start writing fast and has great features.

    Take a look here to get started: http://demo.sugoijs.com/ , documentation: https://wiki.sugoijs.com/

    It has request handling decorators, request policies and authorization policies decorators.

    For example:

    import {Controller,Response,HttpGet,RequestParam} from "@sugoi/server";
    ​
    @Controller('/dashboard')
    export class CoreController{
        constructor(){}
    ​
        @HttpGet("/:role")
        test(@RequestParam('role') role:string,
             @RequestHeader("role") headerRole:string){
            if(role === headerRole )
                return "authorized";
            else{
                throw new Error("unauthorized")
            }
        }
    }
    

提交回复
热议问题