This repository has been archived by the owner on Aug 22, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
209 additions
and
0 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,6 @@ | ||
native/target | ||
native/index.node | ||
native/artifacts.json | ||
**/*~ | ||
**/node_modules | ||
**/.DS_Store |
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,3 @@ | ||
# middleware | ||
|
||
Nuxt Server Middleware |
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,3 @@ | ||
const { middleware } = require('../native') | ||
|
||
export default middleware |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
[package] | ||
name = "middleware" | ||
version = "0.1.0" | ||
authors = ["Jonas Galvez <jonasgalvez@gmail.com>"] | ||
license = "MIT" | ||
build = "build.rs" | ||
exclude = ["artifacts.json", "index.node"] | ||
|
||
[lib] | ||
name = "middleware" | ||
crate-type = ["dylib"] | ||
|
||
[build-dependencies] | ||
neon-build = "0.2.0" | ||
|
||
[dependencies] | ||
neon = "0.2.0" |
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,7 @@ | ||
extern crate neon_build; | ||
|
||
fn main() { | ||
neon_build::setup(); // must be called in build.rs | ||
|
||
// add project-specific build logic here... | ||
} |
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,31 @@ | ||
#[macro_use] | ||
extern crate neon; | ||
|
||
use neon::prelude::*; | ||
|
||
fn middleware(mut ctx: FunctionContext) -> JsResult<JsUndefined> { | ||
// If we also need the request object: | ||
// let req = ctx.argument::<JsObject>(0)?; | ||
let res = ctx.argument::<JsObject>(1)?; | ||
let next = ctx.argument::<JsFunction>(2)?; | ||
|
||
// Create a JsString with the Neon helper | ||
let message = ctx.string("Hello from Rust"); | ||
res.set(&mut ctx, "neonMessage", message)?; | ||
|
||
// Empt argument list for next(), must be Vec<Handle> | ||
let args: Vec<Handle<JsValue>> = vec![]; | ||
// Get a null reference with the Neon helper | ||
let null = ctx.null(); | ||
// Call serverMiddleware's next() function | ||
next.call(&mut ctx, null, args)?; | ||
|
||
// Must return JsUndefined | ||
Ok(ctx.undefined()) | ||
} | ||
|
||
// Neon has no support for default exports yet | ||
register_module!(mut ctx, { | ||
ctx.export_function("middleware", middleware) | ||
}); | ||
|
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,14 @@ | ||
{ | ||
"name": "middleware", | ||
"version": "0.1.0", | ||
"description": "Nuxt Server Middleware", | ||
"main": "lib/index.js", | ||
"author": "Jonas Galvez <jonasgalvez@gmail.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"neon-cli": "^0.2.0" | ||
}, | ||
"scripts": { | ||
"install": "neon build" | ||
} | ||
} |