Skip to content

Commit

Permalink
Add ssx-quickstart-express example (#96)
Browse files Browse the repository at this point in the history
* 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
w4ll3 and skgbafa committed Feb 28, 2023
1 parent 88db60d commit 2efb331
Show file tree
Hide file tree
Showing 7 changed files with 1,396 additions and 67 deletions.
2 changes: 2 additions & 0 deletions examples/ssx-quickstart-express/.env.example
@@ -0,0 +1,2 @@
SSX_SECRET=
PORT=
2 changes: 2 additions & 0 deletions examples/ssx-quickstart-express/.gitignore
@@ -0,0 +1,2 @@
.env
node_modules
18 changes: 18 additions & 0 deletions examples/ssx-quickstart-express/README.md
@@ -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.
23 changes: 23 additions & 0 deletions examples/ssx-quickstart-express/package.json
@@ -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"
}
}
26 changes: 26 additions & 0 deletions examples/ssx-quickstart-express/src/index.ts
@@ -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}`);
});

0 comments on commit 2efb331

Please sign in to comment.