aaronwlee / attain Goto Github PK
View Code? Open in Web Editor NEWDeno API middleware Server
Home Page: https://aaronwlee.github.io/Attain/
License: MIT License
Deno API middleware Server
Home Page: https://aaronwlee.github.io/Attain/
License: MIT License
`POST undefined /api/getfileinfo``
what is res.pend, how its work
Deno version: 1.2.1
Attain version: 1.0.9
Good morning/evening,
I've been trying to install the new version of the cli and got this error:
error: Import 'https://deno.land/x/[email protected]/viewEngine/ReactCompiler.tsx' failed: 404 Not Found Imported from "https://deno.land/x/[email protected]/cli/build.ts:2"
as you can see, the ReactCompiler.tsx file is missing.
How to keep app running then connection to db was lost? For now deno process is just die.
//connect ot DB
var db=await connect(...)
const app = new App()
app.use((req,res)=>{...})
error: Uncaught BadResource: Bad resource ID
at unwrapResponse ($deno$/ops/dispatch_minimal.ts:63:11)
at Object.sendAsyncMinimal ($deno$/ops/dispatch_minimal.ts:106:10)
at async Object.read ($deno$/ops/io.ts:39:17)
at async Object.copy ($deno$/io.ts:64:20)
at async writeResponse (https://deno.land/std/http/_io.ts:264:15)
at async ServerRequest.respond (https://deno.land/std/http/server.ts:88:7)
at async Process.finalize (https://deno.land/x/attain/process.ts:92:7)
at async App.handleRequest (https://deno.land/x/attain/application.ts:18:5)
Please add this feature
app.listen(2000, '192.168.56.1')
I was thinking, what if we could do something like this:
class MyDatabase implements AttainDatabase { /* methods for communicating with the database, such as: */ async findAllUsers(){ return await database.query('SELECT * FROM users'); } }
the AttainDatabase interface will contain a connect method.
and then, provide a method with a generic class that implemets AttainDatabase:
app.database<MyDatabase>()
and provide a database instance in the handler functions!
that way, you will be able to change your database with just one line of code!
consider refering to my repo where I did something similar
thoughts?
In an Express Node.js application I would specify an error handling route like this:
app.use(function(err, req, res, next) {
//error handling stuff here
});
and I would expect this to run as the next handler whenever I throw an Error
in one of my routes. However, this feature doesn't seem to be present in Attain
. I get the following error upon compilation:
No overload matches this call.
The last overload gave the following error.
Argument of type '(err: any, req: any, res: any, next: any) => void' is not assignable to parameter of type 'string'.ts(2769)
I can work around this problem by adding some try-catch
statements around my code but let me know if there's a better solution I have not thought of. Thanks!
For express/node we have req stream pipe to file on disk, so do we have this option in deno?
hey again is there any way to use router.param() function
We also need session middleware like exspres-session for identify all request, do you have any ideas?
Hi, It's cool framework!
I recently create a web boilerplate with Attain, I find something weird behavior on req.query
.
In ExpressJS when I have URL without query params, it returns empty object {}
on console.log(req.query)
.
I try using Attain and it returns { : "" }
on console.log(req.query)
. I am afraid if someone might need to check whether the url has query params using Object.keys(req.query).length
it will return an error.
I don't know the best way to check query params exist or not besides using Object.keys(req.query).length
or is there any plan to make kind of query params checker?
Hi!
Do we have any alternative in deno to run server on all available CPUs in parallel, like cluster/pm2 module in node.js?
In express for example, a route like /hello?name=JohnSmith
, can be parsed using req.query
to get an object {name: "JohnSmith"}
.
I can't find anything similar in Attain. I am aware of the parser
plugin, but it only parses the body.
How to hide this header?
x-powered-by: Deno.js, Attain v0.5
error: TS2502 [ERROR]: 'thisArg' is referenced directly or indirectly in its own type annotation.
bind(this: T, thisArg: ThisParameterType): OmitThisParameter;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at asset:///lib.es5.d.ts:350:22
TS2577 [ERROR]: Return type annotation circularly references itself.
bind(this: T, thisArg: ThisParameterType): OmitThisParameter;
~~~~~~~~~~~~~~~~~~~~
at asset:///lib.es5.d.ts:350:54
TS2339 [ERROR]: Property 'transpileOnly' does not exist on type 'typeof Deno'.
const result = await Deno.transpileOnly({
~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/viewEngine/ReactCompiler.ts:118:33
Found 3 errors.
How to add handler for websocket connections?
If there is anything I can do I'll be happy to help.
I tried to build Attain, but it doesn't work. Apparently, it is referring to a repository that does not exist.
Download https://deno.land/[email protected]/path/_constants.ts
Download https://deno.land/[email protected]/path/_util.ts
Download https://deno.land/[email protected]/path/_constants.ts
Download https://deno.land/[email protected]/path/_util.ts
Download https://deno.land/[email protected]/path/_constants.ts
Download https://deno.land/[email protected]/path/_util.ts
Download https://deno.land/[email protected]/path/_constants.ts
Download https://deno.land/[email protected]/path/_util.ts
Download https://deno.land/[email protected]/testing/diff.ts
Download https://deno.land/[email protected]/testing/diff.ts
Download https://deno.land/[email protected]/testing/diff.ts
Download https://deno.land/[email protected]/testing/diff.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/http/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/http/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/http/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/http/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/http/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/http/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
Download https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts
error: Import 'https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/index.d.ts' failed: 500 Internal Server Error
How to get client ip address?
please work on your website
My code:
import { App, Router } from "https://deno.land/x/[email protected]/mod.ts";
const app = new App();
app.get("/:id", (req, res) => {
console.log(req.params);
res.status(200).send(`id: ${req.params.id}`);
});
app.listen({ port: 1001 }); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Error: Argument of type '{ port: number; }' is not assignable to parameter of type 'number'.deno-ts(2345)
Will be cool to implement simple example for benchmark node (express) and deno (attain) and compare it speed.
Hey, love this framework
& is there any way to turn off the logs because these things are awesome during the development but unnecessary during production.
{ method: "GET", url: "/block", callBack: [AsyncFunction] }
{ method: "GET", url: "/nonblock", callBack: [Function] }
{ method: "GET", url: "/nonblock", callBack: [Function] }
{ method: "ALL", callBack: [AsyncFunction: parser] }
{
method: "ALL",
url: "/api(.*)",
next: [ { method: "GET", url: "/api/nonblock", callBack: [Function], next: undefined } ]
}
{
method: "ALL",
url: "/api/article(.*)",
next: [
{
method: "GET",
url: "/api/article/block",
callBack: [AsyncFunction],
next: undefined
},
{
method: "GET",
url: "/api/article/nonblock",
callBack: [Function],
next: undefined
}
]
}
{ method: "ALL", callBack: [Function] }
I thing this will be the next express framework keep it up before you know it this will be the default framework for Deno
Issue description: ako-deno/negotiator#1
I beleaveThis also requires a number of attain's dependency updates
error: TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
Response
~~~~~~~~
at https://deno.land/x/[email protected]/deps.ts:6:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
Deferred
~~~~~~~~
at https://deno.land/x/[email protected]/deps.ts:19:3
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { ErrorStatus } from "./types.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/httpError.ts:30:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import {
^
at https://deno.land/x/[email protected]/core/response.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { AttainResponse, CallBackType } from "./types.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/response.ts:8:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Request } from "./request.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/utils.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Response } from "./response.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/utils.ts:2:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { BufReader } from "./buf_reader.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/headers.ts:3:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { ServerRequest } from "../deps.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/request.ts:39:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { SupportMethodType } from "./types.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/request.ts:40:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Response as DenoResponse, Status } from "../deps.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/types.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Request } from "./request.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/types.ts:2:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Response } from "./response.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/types.ts:3:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import {
^
at https://deno.land/x/[email protected]/core/router.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { ErrorCallBackType } from "../mod.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/defaultHandler/defaultError.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { CallBackType } from "../mod.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/defaultHandler/defaultPageNotFound.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { ServerRequest } from "../deps.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/process.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import {
^
at https://deno.land/x/[email protected]/core/process.ts:5:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { MiddlewareProps, ErrorMiddlewareProps } from "./types.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/debug.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { ListenProps, ThenArg } from "./types.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/application.ts:11:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { AttainDatabase, NoParamConstructor } from "./database.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/core/application.ts:16:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Request, Response } from "../mod.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/plugins/parser.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Request, Response } from "../mod.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/plugins/logger.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Request, Response } from "../mod.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/plugins/staticServe.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Request, Response } from "../mod.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/helmat/x-xxs-protection.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Request, Response } from "../mod.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/helmat/hide-powered-by.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Request, Response } from "../mod.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/helmat/dns-prefetch-control.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Request, Response } from "../mod.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/helmat/dont-sniff-mimetype.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Request, Response } from "../mod.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/helmat/frame-guard.ts:1:1
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Request, Response } from "../mod.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/plugins/security.ts:1:1
Found 30 errors.
Hello there!
I was trying to run your CLI with the command you put in your repo:
$ deno install -A -f --unstable -n attain https://deno.land/x/[email protected]/attain-cli.ts
when I did, deno cached all of the dependencies and then outputted this error:
error: TS2345 [ERROR]: Argument of type '{ depth: number; sorted: boolean; trailingComma: boolean; compact: boolean; iterableLimit: number; }' is not assignable to parameter of type 'InspectOptions'. Object literal may only specify known properties, and 'sorted' does not exist in type 'InspectOptions'. sorted: true, ~~~~~~~~~~~~ at https://deno.land/[email protected]/testing/asserts.ts:26:9
are you familiar with this problem? I also tried to run v1.0.0 but it outputted the same problem again.
I found another bug here. When I put a middleware within the first route, second route, third route, and so on didnt work, it always return to the first route.
When I access /
endpoint, it return Hello Welcome to Deno
.
When I access other endpoint /users
and /query
it also return Hello Welcome to Deno
.
When I move the exampleMiddleware
to second route, the /users
endpoint works, the third route /query
will return the same value as second route /users
.
Suppose I have this code on my router
route.get('/', exampleMiddleware, (req: Request, res: Response) => {
res.send({
status: 200,
text: 'Hello Welcome to Deno'
})
});
route.get('/users', async (req: Request, res: Response) => {
let getUsers = await users.getUsers();
return res.send({
status: 200,
data: getUsers
});
});
route.get('/query', (req: Request, res: Response) => {
res.send({
status: 200,
text: 'Middleware query params passed'
})
});
And here is my exampleMiddleware code
function exampleMiddleware (req: Request, res: Response):any {
if (!req.query) {
return res.status(200).send({
status: 500,
response: 'Cant pass without query params'
})
}
}
What returns on debug mode
{ method: "GET", url: "/", callBack: [Function: exampleMiddleware] }
{ method: "GET", callBack: [Function] }
{ method: "GET", url: "/users", callBack: [AsyncFunction] }
{ method: "GET", url: "/query", callBack: [Function] }
{ method: "ALL", callBack: [Function: logger] }
{ method: "ALL", callBack: [AsyncFunction: parser] }
{ method: "ALL", callBack: [AsyncFunction] }
{
method: "ALL",
url: "/api(.*)",
next: [
{
method: "GET",
url: "/api",
callBack: [Function: exampleMiddleware],
next: undefined
},
{ method: "GET", callBack: [Function] },
{ method: "GET", url: "/api/users", callBack: [AsyncFunction], next: undefined },
{ method: "GET", url: "/api/query", callBack: [Function], next: undefined }
]
}
{ method: "ALL", url: "/", callBack: [Function] }
http://localhost:3500
Express have res.download(..) method https://expressjs.com/ru/api.html#res.download to handle file downloading for user action in browser, is it any alternative here?
Is it https is supported for creating server?
error: TS2339 [ERROR]: Property 'authorization' does not exist on type 'Headers'.
console.log(req.headers.authorization);
~~~~~~~~~~~~~
at file:///C:/Users/Asad/Documents/re/deno-api/routes/user.ts:38:27
router.get("/", async (req, res) => {
console.log(req.headers.authorization);
res.status(200).send("hi");
})
I think we need CORS middleware to allow access from other server/client.
Looks line this not working then I request from browser: /js/index.js
but if i just simple request /js
then working first middleware.
app.use("/js",(req,res)=>{...});
or
app.use("/js*",(req,res)=>{...});
Hello
I try to do a simple exercise with deno and Attain and I've had this error
`error: TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'.
Type 'URL' is not assignable to type 'string'.
return new URL(url).pathname
~~~
at https://deno.land/[email protected]/path/win32.ts:911:18
TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'.
Type 'URL' is not assignable to type 'string'.
return new URL(url).pathname;
~~~
at https://deno.land/[email protected]/path/posix.ts:433:18
Found 2 errors.`
Mi code is this:
`import { App } from 'https://deno.land/x/attain/mod.ts';
const app = new App();
app.listen( {
port: 3000
})
console.log('server running localhost:3000')`
I don't understand what happens, Is possible a global error?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.