Estoy tratando de levantar un servidor web para servir HTML mediante deno, tenía entendido que se usaba el Fetch API, pero al tratar lanzar tuve que hacer pruebay error para crear un objeto response.
import * as express from "https://raw.githubusercontent.com/NMathar/deno-express/master/mod.ts";
const PORT_NUMBER: number = 8085;
const app: express.App = new express.App();
// Middleware
app.use(express.simpleLog());
app.use(express.bodyParser.urlencoded());
app.use(express.static_('./'));
// Rutas
app.get('/', (req, res: Response) => {
let headers = new Array<String>();
headers["Content-Type"] = ["text/html"];
res = new Response("<h1>hello world!</h1>", 200, "ok", headers, 1, false);
});
const server = await app.listen(PORT_NUMBER);
console.log("app listening on PORT_NUMBER " + server.port);
El error que me arroja es:
deno run server.ts
error: TS2345 [ERROR]: Argument of type '(req: Request, res: Response)
=> void' is not assignable to parameter of type 'EndHandler'. Types of parameters 'res' and 'res' are incompatible.
Type 'Response' is missing the following properties from type 'Response': ok, redirected, statusText, trailer, and 8 more. app.get('/', (req, res: Response) => { ~~~~~~~~~~~~~~~~~~~~~~~~~ at file:///C:/Users/RuslanLopez/IdeaProjects/ragaman/server.ts:12:14
TS7015 [ERROR]: Element implicitly has an 'any' type because index
expression is not of type 'number'.
headers["Content-Type"] = ["text/html"]; ~~~~~~~~~~~~~~ at file:///C:/Users/RuslanLopez/IdeaProjects/ragaman/server.ts:14:13
TS2345 [ERROR]: Argument of type 'String[]' is not assignable to
parameter of type '[string, string][]'. Type 'String' is not
assignable to type '[string, string]'.
res = new Response("<h1>hello world!</h1>", 200, "ok", headers, 1, false); ~~~~~~~ at file:///C:/Users/RuslanLopez/IdeaProjects/ragaman/server.ts:15:60
Found 3 errors.
Lo que más me turba es el que dice que se esperaba un tipo [string, string][]
, cosa que no se me ocurre como declarar.
app.get("/foo", async (req, res) => { foo..})
, me avisas que tal te fue.