Skip to content

Commit

Permalink
refactor: 💡 add ncc build for socios-oauth2
Browse files Browse the repository at this point in the history
  • Loading branch information
abcfy2 committed Sep 12, 2023
1 parent 4d09140 commit ca50280
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 25 deletions.
3 changes: 2 additions & 1 deletion socios-oauth2/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.ENV
node_modules
node_modules
dist/
34 changes: 18 additions & 16 deletions socios-oauth2/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from "path";
import express from "express";
import { Server } from "@tokenscript/token-negotiator-server";
import { fileURLToPath } from 'url';
import { fileURLToPath } from "url";
import bodyParser from "body-parser";
import cookieParser from "cookie-parser";
import cors from 'cors';
import 'dotenv/config'
import cors from "cors";
import "dotenv/config";

const app = express();
const port = 5000;
Expand All @@ -17,7 +17,7 @@ const __dirname = path.dirname(__filename);
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(express.static("public"));
app.use(express.static(path.join(__dirname, "public")));

const tokenNegotiatorServer = new Server({
issuers: {
Expand All @@ -28,23 +28,25 @@ const tokenNegotiatorServer = new Server({
partnerTag: process.env.SOCIOS_PARTNER_TAG,
redirectURI: process.env.SOCIOS_REDIRECT_URI,
returnToApplicationURL: process.env.SOCIOS_RETURN_TO_APP_URL,
}
}
},
},
});

const corsOptions = { origin: process.env.APPLICATION_URL }
const corsOptions = { origin: process.env.APPLICATION_URL };

app.get("/", function (request, response) {
response.sendFile(path.join(__dirname, "./public/index.html"));
});

app.get("/user-login-callback", async (request, response) => {

const accessTokenData = await tokenNegotiatorServer.socios.getAccessToken(request.query.code, response);
const accessTokenData = await tokenNegotiatorServer.socios.getAccessToken(
request.query.code,
response
);

tokenNegotiatorServer.utils.setAccessTokenCookie(
response,
'socios',
"socios",
accessTokenData
);

Expand All @@ -53,17 +55,17 @@ app.get("/user-login-callback", async (request, response) => {
});

app.get("/user-balance", cors(corsOptions), async (request, response) => {
const output = await tokenNegotiatorServer.socios.getFungibleTokenBalance(request.cookies['tn-oauth2-access-token-socios']);
const output = await tokenNegotiatorServer.socios.getFungibleTokenBalance(
request.cookies["tn-oauth2-access-token-socios"]
);
response.json(output);
});

app.get("/user-nfts", cors(corsOptions), async (request, response) => {
const output = await tokenNegotiatorServer.socios.getNonFungibleTokens(request.cookies['tn-oauth2-access-token-socios']);
const output = await tokenNegotiatorServer.socios.getNonFungibleTokens(
request.cookies["tn-oauth2-access-token-socios"]
);
response.json(output);
});

app.listen(port, () => console.info(`App listening on port ${port}`));




112 changes: 105 additions & 7 deletions socios-oauth2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion socios-oauth2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js",
"link": "npm link ../token-negotiator",
"unlink": "npm unlink ../token-negotiator"
"unlink": "npm unlink ../token-negotiator",
"build": "ncc build app.js -sm"
},
"author": "",
"license": "ISC",
Expand All @@ -24,6 +25,7 @@
"node-fetch": "^3.3.2"
},
"devDependencies": {
"@vercel/ncc": "^0.38.0",
"nodemon": "^2.0.4"
}
}

0 comments on commit ca50280

Please sign in to comment.