-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: correctly handle import statement with JSR specifier (#336)
* fix: we should handle jsr specifier now since deno HQ seems to have decided to use it on prod * stamp: add an integration test for import statement with jsr specifier * stamp: add an example for import statement with jsr specifier * stamp(base): unpin oak version in `test_cases` * stamp: update oak related integration tests
- Loading branch information
1 parent
1bf0900
commit 0648aa0
Showing
6 changed files
with
103 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Application, Router } from 'https://deno.land/x/[email protected]/mod.ts'; | ||
|
||
const MB = 1024 * 1024; | ||
|
||
const router = new Router(); | ||
|
||
router | ||
.post('/file-upload', async (ctx) => { | ||
try { | ||
const body = ctx.request.body({ type: 'form-data' }); | ||
const formData = await body.value.read({ | ||
// Need to set the maxSize so files will be stored in memory. | ||
// This is necessary as Edge Functions don't have disk write access. | ||
// We are setting the max size as 10MB (an Edge Function has a max memory limit of 150MB) | ||
// For more config options, check: https://deno.land/x/[email protected]/mod.ts?s=FormDataReadOptions | ||
maxSize: 1 * MB, | ||
}); | ||
const file = formData.files[0]; | ||
|
||
ctx.response.status = 201; | ||
ctx.response.body = `file-type: ${file.contentType}`; | ||
} catch (e) { | ||
console.log('error occurred'); | ||
console.log(e); | ||
ctx.response.status = 500; | ||
ctx.response.body = 'Error!'; | ||
} | ||
}); | ||
|
||
const app = new Application(); | ||
|
||
app.use(router.routes()); | ||
app.use(router.allowedMethods()); | ||
|
||
await app.listen(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Application } from "jsr:@oak/oak/application"; | ||
import { Router } from "jsr:@oak/oak/router"; | ||
|
||
const router = new Router(); | ||
|
||
router | ||
// Note: path will be prefixed with function name | ||
.get("/oak-with-jsr", (context) => { | ||
context.response.body = "meow"; | ||
}); | ||
|
||
const app = new Application(); | ||
|
||
app.use(router.routes()); | ||
app.use(router.allowedMethods()); | ||
|
||
await app.listen(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,19 @@ | ||
import { Application, Router } from 'https://deno.land/x/[email protected]/mod.ts'; | ||
|
||
const MB = 1024 * 1024; | ||
import { Application, Router } from 'https://deno.land/x/oak/mod.ts'; | ||
|
||
const router = new Router(); | ||
|
||
router | ||
// Note: path will be prefixed with function name | ||
.get('/oak', (context) => { | ||
context.response.body = 'This is an example Oak server running on Edge Functions!'; | ||
}) | ||
.post('/oak/greet', async (context) => { | ||
// Note: request body will be streamed to the function as chunks, set limit to 0 to fully read it. | ||
const result = context.request.body({ type: 'json', limit: 0 }); | ||
const body = await result.value; | ||
const name = body.name || 'you'; | ||
|
||
context.response.body = { msg: `Hey ${name}!` }; | ||
}) | ||
.get('/oak/redirect', (context) => { | ||
context.response.redirect('https://www.example.com'); | ||
}) | ||
.post('/file-upload', async (ctx) => { | ||
try { | ||
const body = ctx.request.body({ type: 'form-data' }); | ||
const formData = await body.value.read({ | ||
// Need to set the maxSize so files will be stored in memory. | ||
// This is necessary as Edge Functions don't have disk write access. | ||
// We are setting the max size as 10MB (an Edge Function has a max memory limit of 150MB) | ||
// For more config options, check: https://deno.land/x/[email protected]/mod.ts?s=FormDataReadOptions | ||
maxSize: 1 * MB, | ||
}); | ||
const file = formData.files[0]; | ||
|
||
ctx.response.status = 201; | ||
ctx.response.body = `file-type: ${file.contentType}`; | ||
} catch (e) { | ||
console.log('error occurred'); | ||
console.log(e); | ||
ctx.response.status = 500; | ||
ctx.response.body = 'Error!'; | ||
} | ||
}); | ||
|
||
const app = new Application(); | ||
|
||
app.use(router.routes()); | ||
app.use(router.allowedMethods()); | ||
|
||
await app.listen({ port: 8000 }); | ||
await app.listen(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Application } from "jsr:@oak/oak/application"; | ||
import { Router } from "jsr:@oak/oak/router"; | ||
|
||
const router = new Router(); | ||
|
||
router | ||
// Note: path will be prefixed with function name | ||
.get("/oak-with-jsr", (context) => { | ||
context.response.body = "This is an example Oak server running on Edge Functions!"; | ||
}); | ||
|
||
const app = new Application(); | ||
|
||
app.use(router.routes()); | ||
app.use(router.allowedMethods()); | ||
|
||
await app.listen(); |