Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ssx-quickstart-express example (#96)
* Add ssx-quickstart-express example * Add README * Update response message Co-authored-by: Sam Gbafa <skgbafa@gmail.com> * Security improvements * added env example * Update yarn lock --------- Co-authored-by: Sam Gbafa <skgbafa@gmail.com>
- Loading branch information
Showing
7 changed files
with
1,396 additions
and
67 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,2 @@ | ||
SSX_SECRET= | ||
PORT= |
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,2 @@ | ||
.env | ||
node_modules |
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,18 @@ | ||
# ssx-quickstart-express | ||
## Overview | ||
This is a simple example on how to setup a SSX Server with Express.js. For a step by step guide head to | ||
https://docs.ssx.id/ssx-server-quickstart. | ||
|
||
## Running | ||
Prepare by creating and editing the secrets in the `.env` file. You can use the `.env.example` as a template. | ||
```bash | ||
cp .env.example .env | ||
``` | ||
|
||
To run the example, first install the dependencies and then start the server. | ||
```bash | ||
yarn && yarn start | ||
``` | ||
|
||
The ssx-test-dapp is compatible with this example and is a good interface to test it. Note that some functionalities | ||
might need extra configuration in order to properly work. |
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,23 @@ | ||
{ | ||
"name": "ssx-quickstart-express", | ||
"version": "0.1.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"private": "true", | ||
"scripts": { | ||
"start": "ts-node src/index" | ||
}, | ||
"devDependencies": { | ||
"@types/cors": "^2.8.13", | ||
"@types/express": "^4.17.17", | ||
"@types/node": "^18.14.2", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.5" | ||
}, | ||
"dependencies": { | ||
"@spruceid/ssx-server": "^1.2.2", | ||
"cors": "^2.8.5", | ||
"dotenv": "^16.0.3", | ||
"express": "^4.18.2" | ||
} | ||
} |
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,26 @@ | ||
import express from 'express'; | ||
import dotenv from 'dotenv'; | ||
import { SSXServer, SSXExpressMiddleware } from '@spruceid/ssx-server'; | ||
import cors from 'cors'; | ||
|
||
dotenv.config(); | ||
const app = express(); | ||
|
||
const ssx = new SSXServer({ | ||
signingKey: process.env.SSX_SECRET, | ||
}); | ||
|
||
const PORT = process.env.PORT || '4000'; | ||
|
||
app.use(cors({ credentials: true, origin: true })); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
app.use(SSXExpressMiddleware(ssx)); | ||
|
||
app.get('/', (_req, res) => { | ||
res.send('SSX Server Online\n'); | ||
}); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`⚡️[server]: Server is running at http://localhost:${PORT}`); | ||
}); |
Oops, something went wrong.