Skip to content

Commit

Permalink
Update the v-server, enable cors (#1548)
Browse files Browse the repository at this point in the history
* Update the v-server, enable cors

* Removed the validation and printed the payload.

* Removed unused comment.

* Added the Vserver to the server docs.
  • Loading branch information
Mahmoud-Emad authored Dec 7, 2023
1 parent 24968cb commit 1535093
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
31 changes: 27 additions & 4 deletions packages/UI/docs/server_verification.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Node.js Server Example for PDF Signature Verification
# Node.js Server Example for PDF/Editor Signature Verification

This Node.js server is designed to facilitate communication between the server and the PDFSigner component. It includes a `verify` endpoint responsible for verifying requested signatures and returning the validation status.
This Node.js server is designed to facilitate communication between the server and the `(PDFSigner, ScriptEditor)` components. It includes a `verify` endpoint responsible for verifying requested signatures and returning the validation status.

# Vlang Server Example for PDF/Editor Signature Verification

This Vlang server is designed to facilitate communication between the server and the `(PDFSigner, ScriptEditor)` components. It includes a `verify` endpoint responsible for printing out the request payload.

## Usage

Expand Down Expand Up @@ -32,6 +36,17 @@ let payLoad: Payload = {
};
```

The expected request body follows this Vlang pattern:

```vlang
payLoad := {
twinid: 0,
pdf_url: "",
pubkey: "",
signature: "",
};
```

### Response Format

#### Verified Signature
Expand Down Expand Up @@ -64,8 +79,16 @@ If the signature cannot be verified, the server will respond with an HTTP status

### How to run the server

- NodeJS server

```sh
$server_example/nodejs-server npx ts-node src/server.ts
```

- Vlang server

```sh
$server_example npx ts-node src/server.ts
$server_example/vlang-server v run main.v
```

Use this Node.js server example to handle PDF signature verification within your application.
Use this NodeJS/Vlang servers examples to handle PDF/Editor signature verification within your application.
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
module local_server

import vweb
import time
import x.json2


pub fn (app &VServerApp) before_request() {
pub fn (mut app VServerApp) before_request() {
eprintln('${time.now()}: ${app.req.method} ${app.req.url}')
}

@['/api/verify'; post]
@[options;'/:path...']
pub fn (mut app VServerApp) preflight(path string) vweb.Result {
app.add_header('Vary', 'Access-Control-Request-Headers')
app.add_header('Access-Control-Allow-Methods', 'GET,HEAD,PUT,PATCH,POST,DELETE')
app.add_header('Access-Control-Allow-Headers', 'Content-Type')
app.add_header('Access-Control-Allow-Origin', '*')

return app.text('options are ok')
}

@['/api/verify'; POST]
pub fn (mut app VServerApp) verify() vweb.Result {
data := app.req.data
payload := json2.decode[Payload](data) or {
app.set_status(400, "")
return app.json({
"Error": "true",
"message": "Please make sure that you sent a valid date."
"required_fields": Payload{}.str()
"status": '400'
})
}

println(payload)
app.add_header('Access-Control-Allow-Origin', '*')
app.set_status(200, "")
data := app.req.data
println("Payload: ${data}")
return app.json({
"data": "id"
"data": data
})

}
2 changes: 1 addition & 1 deletion packages/UI/examples/server-example/vlang-server/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import local_server

fn main (){
config := local_server.VServerConfig{
port: 2000
port: 3000
}

server := local_server.init(config)
Expand Down

0 comments on commit 1535093

Please sign in to comment.