@prosopo/client-example-server 1.0.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -4
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +29 -22
- package/dist/app.js.map +1 -1
- package/dist/controllers/auth.d.ts +3 -3
- package/dist/controllers/auth.d.ts.map +1 -1
- package/dist/controllers/auth.js +70 -56
- package/dist/controllers/auth.js.map +1 -1
- package/dist/models/user.d.ts +7 -2
- package/dist/models/user.d.ts.map +1 -1
- package/dist/models/user.js +1 -1
- package/dist/models/user.js.map +1 -1
- package/dist/routes/routes.d.ts +4 -3
- package/dist/routes/routes.d.ts.map +1 -1
- package/dist/routes/routes.js +9 -9
- package/dist/routes/routes.js.map +1 -1
- package/dist/utils/connection.d.ts +2 -1
- package/dist/utils/connection.d.ts.map +1 -1
- package/dist/utils/connection.js +7 -5
- package/dist/utils/connection.js.map +1 -1
- package/dist/utils/database.d.ts.map +1 -1
- package/dist/utils/database.js +1 -1
- package/dist/utils/database.js.map +1 -1
- package/package.json +50 -58
- package/typedoc.config.js +11 -5
- package/vite.config.ts +26 -18
package/README.md
CHANGED
|
@@ -5,11 +5,38 @@ is based
|
|
|
5
5
|
on [an article written by Agustin Fernandez](https://www.asapdevelopers.com/build-a-react-native-login-app-with-node-js-backend/)
|
|
6
6
|
and is adapted to use a Mongo In-Memory Database. This backend server integrates with the client-example React app.
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Quickstart
|
|
9
9
|
|
|
10
|
-
###
|
|
10
|
+
### Test Your Site Key and Secret Key
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
#### 1. Build & Deploy
|
|
13
|
+
|
|
14
|
+
From the root of this repository, run the following commands:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
cp demos/client-example-server/env.production demos/client-example-server/.env.production && \
|
|
18
|
+
npm i && \
|
|
19
|
+
npm run start:server
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Make sure you replace the following placeholders in the `.env.production` file with your own site key and secret key.
|
|
23
|
+
You can obtain these by logging into the [Prosopo portal](https://portal.prosopo.io).
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
PROSOPO_SITE_KEY=<YOUR SITE KEY HERE>
|
|
27
|
+
PROSOPO_SITE_PRIVATE_KEY=<YOUR SECRET KEY HERE>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Run this example API in conjunction with
|
|
31
|
+
the [client-example](https://github.com/prosopo/captcha/tree/main/demos/client-example) React app.
|
|
32
|
+
|
|
33
|
+
## 🚧 Developing the Client Example Server
|
|
34
|
+
|
|
35
|
+
You can run in development mode to make changes to the client-example-server by following these instructions:
|
|
36
|
+
|
|
37
|
+
### Build & Deploy
|
|
38
|
+
|
|
39
|
+
From the root of this repository, run the following commands:
|
|
13
40
|
|
|
14
41
|
```bash
|
|
15
42
|
cp demos/client-example-server/env.development demos/client-example-server/.env.development && \
|
|
@@ -21,7 +48,7 @@ npm run setup:all && \
|
|
|
21
48
|
npm run start:server
|
|
22
49
|
```
|
|
23
50
|
|
|
24
|
-
###
|
|
51
|
+
### Use the API
|
|
25
52
|
|
|
26
53
|
The server should now be running at localhost:9228. You can customise this in the `.env.development` file. Run this
|
|
27
54
|
example API in conjunction with the [client-example](https://github.com/prosopo/captcha/tree/main/demos/client-example)
|
package/dist/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAwBA,wBAAgB,OAAO,SAEtB;AAED,wBAAgB,UAAU,CAAC,QAAQ,SAAS,EAAE,QAAQ,SAAO,UAG5D"}
|
package/dist/app.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { ProsopoEnvError, getLoggerDefault } from "@prosopo/common";
|
|
3
|
+
import { getServerConfig } from "@prosopo/server";
|
|
4
|
+
import { at } from "@prosopo/util";
|
|
5
|
+
import cors from "cors";
|
|
6
|
+
import dotenv from "dotenv";
|
|
7
|
+
import express from "express";
|
|
8
|
+
import routesFactory from "./routes/routes.js";
|
|
9
|
+
import connectionFactory from "./utils/connection.js";
|
|
10
|
+
import memoryServerSetup from "./utils/database.js";
|
|
10
11
|
export function loadEnv() {
|
|
11
12
|
dotenv.config({ path: getEnvFile() });
|
|
12
13
|
}
|
|
13
|
-
export function getEnvFile(filename =
|
|
14
|
-
const env = process.env.NODE_ENV ||
|
|
14
|
+
export function getEnvFile(filename = ".env", filepath = "./") {
|
|
15
|
+
const env = process.env.NODE_ENV || "development";
|
|
15
16
|
return path.join(filepath, `${filename}.${env}`);
|
|
16
17
|
}
|
|
17
18
|
var ProsopoVerificationType;
|
|
@@ -22,7 +23,11 @@ var ProsopoVerificationType;
|
|
|
22
23
|
async function main() {
|
|
23
24
|
const logger = getLoggerDefault();
|
|
24
25
|
loadEnv();
|
|
25
|
-
const
|
|
26
|
+
const apiPrefix = process.env.NODE_ENV && process.env.NODE_ENV === "production"
|
|
27
|
+
? ""
|
|
28
|
+
: `${process.env.NODE_ENV}-`;
|
|
29
|
+
const verifyEndpoint = process.env.PROSOPO_VERIFY_ENDPOINT ||
|
|
30
|
+
`https://${apiPrefix}api.prosopo.io/siteverify`;
|
|
26
31
|
const verifyType = Object.keys(ProsopoVerificationType).includes(process.env.PROSOPO_VERIFICATION_TYPE)
|
|
27
32
|
? process.env.PROSOPO_VERIFICATION_TYPE
|
|
28
33
|
: ProsopoVerificationType.api;
|
|
@@ -31,32 +36,34 @@ async function main() {
|
|
|
31
36
|
app.use(express.urlencoded({ extended: true }));
|
|
32
37
|
app.use(express.json());
|
|
33
38
|
app.use((_, res, next) => {
|
|
34
|
-
res.setHeader(
|
|
35
|
-
res.setHeader(
|
|
36
|
-
res.setHeader(
|
|
39
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
40
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE");
|
|
41
|
+
res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, X-Auth-Token, Authorization");
|
|
37
42
|
next();
|
|
38
43
|
});
|
|
39
|
-
app.options(
|
|
44
|
+
app.options("/*", (_, res) => {
|
|
40
45
|
res.sendStatus(200);
|
|
41
46
|
});
|
|
42
47
|
const uri = await memoryServerSetup();
|
|
43
|
-
console.log(
|
|
48
|
+
console.log("mongo uri", uri);
|
|
44
49
|
const mongoose = connectionFactory(uri);
|
|
45
50
|
if (!process.env.PROSOPO_SITE_PRIVATE_KEY) {
|
|
46
|
-
const mnemonicError = new ProsopoEnvError(
|
|
47
|
-
context: { missingParams: [
|
|
51
|
+
const mnemonicError = new ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
|
|
52
|
+
context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] },
|
|
48
53
|
logger,
|
|
49
54
|
});
|
|
50
55
|
logger.error(mnemonicError);
|
|
51
56
|
}
|
|
52
57
|
const config = getServerConfig();
|
|
53
|
-
console.log(
|
|
58
|
+
console.log("Config", config);
|
|
54
59
|
app.use(routesFactory(mongoose, config, verifyEndpoint, verifyType));
|
|
55
|
-
app.listen(
|
|
60
|
+
app.listen(config.serverUrl
|
|
61
|
+
? Number.parseInt(at(config.serverUrl.split(":"), 2))
|
|
62
|
+
: 9228);
|
|
56
63
|
}
|
|
57
64
|
main()
|
|
58
65
|
.then(() => {
|
|
59
|
-
console.log(
|
|
66
|
+
console.log("Server started");
|
|
60
67
|
})
|
|
61
68
|
.catch((err) => {
|
|
62
69
|
console.log(err);
|
package/dist/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAc7B,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AACnC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAC/C,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AACtD,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAEpD,MAAM,UAAU,OAAO;IACrB,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,QAAQ,GAAG,MAAM,EAAE,QAAQ,GAAG,IAAI;IAC3D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;IAClD,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,QAAQ,IAAI,GAAG,EAAE,CAAC,CAAC;AACnD,CAAC;AAED,IAAK,uBAGJ;AAHD,WAAK,uBAAuB;IAC1B,sCAAW,CAAA;IACX,0CAAe,CAAA;AACjB,CAAC,EAHI,uBAAuB,KAAvB,uBAAuB,QAG3B;AAED,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;IAClC,OAAO,EAAE,CAAC;IAEV,MAAM,SAAS,GACb,OAAO,CAAC,GAAG,CAAC,QAA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|
1
|
+
import { type ProsopoServerConfigOutput } from "@prosopo/types";
|
|
2
|
+
import type { NextFunction, Request, Response } from "express";
|
|
3
|
+
import type { Connection } from "mongoose";
|
|
4
4
|
declare const signup: (mongoose: Connection, config: ProsopoServerConfigOutput, verifyEndpoint: string, verifyType: string, req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
5
5
|
declare const login: (mongoose: Connection, config: ProsopoServerConfigOutput, verifyEndpoint: string, verifyType: string, req: Request, res: Response) => Promise<void>;
|
|
6
6
|
declare const isAuth: (req: Request, res: Response) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"AAmBA,OAAO,EAGL,KAAK,yBAAyB,EAC/B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AA2C3C,QAAA,MAAM,MAAM,aACA,UAAU,UACZ,yBAAyB,kBACjB,MAAM,cACV,MAAM,OACb,OAAO,OACP,QAAQ,QACP,YAAY,uDAiEnB,CAAC;AAEF,QAAA,MAAM,KAAK,aACC,UAAU,UACZ,yBAAyB,kBACjB,MAAM,cACV,MAAM,OACb,OAAO,OACP,QAAQ,kBAiEd,CAAC;AAEF,QAAA,MAAM,MAAM,QAAS,OAAO,OAAO,QAAQ,SAqB1C,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/controllers/auth.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import
|
|
1
|
+
import { blake2b } from "@noble/hashes/blake2b";
|
|
2
|
+
import { u8aToHex } from "@polkadot/util";
|
|
3
|
+
import { randomAsHex } from "@polkadot/util-crypto";
|
|
4
|
+
import { ProsopoEnvError } from "@prosopo/common";
|
|
5
|
+
import { getPairAsync } from "@prosopo/contract";
|
|
6
|
+
import { ProsopoServer } from "@prosopo/server";
|
|
7
|
+
import { ApiParams, } from "@prosopo/types";
|
|
8
|
+
import { ProcaptchaResponse } from "@prosopo/types";
|
|
9
|
+
import { at } from "@prosopo/util";
|
|
10
|
+
import jwt from "jsonwebtoken";
|
|
11
|
+
import { z } from "zod";
|
|
12
12
|
const SubscribeBodySpec = ProcaptchaResponse.merge(z.object({
|
|
13
13
|
email: z.string().email(),
|
|
14
14
|
password: z.string(),
|
|
@@ -17,38 +17,38 @@ function hashPassword(password) {
|
|
|
17
17
|
return u8aToHex(blake2b(password));
|
|
18
18
|
}
|
|
19
19
|
const verify = async (prosopoServer, verifyType, verifyEndpoint, token, secret) => {
|
|
20
|
-
if (verifyType ===
|
|
21
|
-
console.log(
|
|
20
|
+
if (verifyType === "api") {
|
|
21
|
+
console.log("Verifying using the API endpoint", verifyEndpoint);
|
|
22
22
|
const response = await fetch(verifyEndpoint, {
|
|
23
|
-
method:
|
|
24
|
-
body: JSON.stringify({
|
|
23
|
+
method: "POST",
|
|
24
|
+
body: JSON.stringify({
|
|
25
|
+
[ApiParams.token]: token,
|
|
26
|
+
[ApiParams.secret]: secret,
|
|
27
|
+
}),
|
|
25
28
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.log('verifying using the TypeScript library');
|
|
30
|
-
return await prosopoServer.isVerified(token);
|
|
29
|
+
const verified = (await response.json()).verified;
|
|
30
|
+
console.log("Verified", verified);
|
|
31
|
+
return verified;
|
|
31
32
|
}
|
|
33
|
+
const verified = await prosopoServer.isVerified(token);
|
|
34
|
+
return verified;
|
|
32
35
|
};
|
|
33
36
|
const signup = async (mongoose, config, verifyEndpoint, verifyType, req, res, next) => {
|
|
34
37
|
try {
|
|
35
|
-
const User = mongoose.model(
|
|
38
|
+
const User = mongoose.model("User");
|
|
36
39
|
const dbUser = await User.findOne({
|
|
37
|
-
email: req.body.email,
|
|
40
|
+
email: { $eq: req.body.email },
|
|
38
41
|
});
|
|
39
42
|
const payload = SubscribeBodySpec.parse(req.body);
|
|
40
43
|
const pair = await getPairAsync(config.networks[config.defaultNetwork], config.account.secret);
|
|
41
44
|
const prosopoServer = new ProsopoServer(config, pair);
|
|
42
|
-
await prosopoServer.isReady();
|
|
43
45
|
if (dbUser) {
|
|
44
|
-
return res.status(409).json({ message:
|
|
46
|
+
return res.status(409).json({ message: "email already exists" });
|
|
45
47
|
}
|
|
46
|
-
console.log('Request payload', payload);
|
|
47
48
|
const token = payload[ApiParams.procaptchaResponse];
|
|
48
|
-
console.log('Sending Procaptcha token', token);
|
|
49
49
|
if (!config.account.secret) {
|
|
50
|
-
throw new ProsopoEnvError(
|
|
51
|
-
context: { missingParams: [
|
|
50
|
+
throw new ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
|
|
51
|
+
context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] },
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
const verified = await verify(prosopoServer, verifyType, verifyEndpoint, token, config.account.secret);
|
|
@@ -63,79 +63,93 @@ const signup = async (mongoose, config, verifyEndpoint, verifyType, req, res, ne
|
|
|
63
63
|
salt: salt,
|
|
64
64
|
})
|
|
65
65
|
.then(() => {
|
|
66
|
-
res.status(200).json({ message:
|
|
66
|
+
res.status(200).json({ message: "user created" });
|
|
67
67
|
})
|
|
68
68
|
.catch((err) => {
|
|
69
69
|
console.log(err);
|
|
70
|
-
res.status(502).json({ message:
|
|
70
|
+
res.status(502).json({ message: "error while creating the user" });
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
else {
|
|
75
|
-
res
|
|
75
|
+
res
|
|
76
|
+
.status(401)
|
|
77
|
+
.json({ message: "user has not completed a captcha", verified });
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
catch (err) {
|
|
79
|
-
console.error(
|
|
80
|
-
res
|
|
81
|
+
console.error("error", err);
|
|
82
|
+
res
|
|
83
|
+
.status(500)
|
|
84
|
+
.json({ message: err.message || "internal server error" });
|
|
81
85
|
}
|
|
82
86
|
};
|
|
83
87
|
const login = async (mongoose, config, verifyEndpoint, verifyType, req, res) => {
|
|
84
|
-
const User = mongoose.model(
|
|
88
|
+
const User = mongoose.model("User");
|
|
85
89
|
const pair = await getPairAsync(config.networks[config.defaultNetwork], config.account.secret);
|
|
86
90
|
const prosopoServer = new ProsopoServer(config, pair);
|
|
87
|
-
await prosopoServer.isReady();
|
|
88
91
|
await User.findOne({
|
|
89
|
-
email: req.body.email,
|
|
92
|
+
email: { $eq: req.body.email },
|
|
90
93
|
})
|
|
91
94
|
.then(async (dbUser) => {
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
else {
|
|
96
|
-
const payload = SubscribeBodySpec.parse(req.body[ApiParams.procaptchaResponse]);
|
|
95
|
+
if (dbUser) {
|
|
96
|
+
console.log(req.body);
|
|
97
|
+
const payload = SubscribeBodySpec.parse(req.body);
|
|
97
98
|
const token = payload[ApiParams.procaptchaResponse];
|
|
98
99
|
if (!config.account.secret) {
|
|
99
|
-
throw new ProsopoEnvError(
|
|
100
|
-
context: { missingParams: [
|
|
100
|
+
throw new ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
|
|
101
|
+
context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] },
|
|
101
102
|
});
|
|
102
103
|
}
|
|
103
104
|
const verified = await verify(prosopoServer, verifyType, verifyEndpoint, token, config.account.secret);
|
|
105
|
+
console.log("verified", verified);
|
|
104
106
|
if (verified) {
|
|
105
107
|
const passwordHash = hashPassword(`${req.body.password}${dbUser.salt}`);
|
|
106
108
|
if (passwordHash !== dbUser.password) {
|
|
107
|
-
res.status(401).json({ message:
|
|
109
|
+
return res.status(401).json({ message: "invalid credentials" });
|
|
108
110
|
}
|
|
109
111
|
else {
|
|
110
|
-
const token = jwt.sign({ email: req.body.email },
|
|
111
|
-
|
|
112
|
+
const token = jwt.sign({ email: req.body.email }, "secret", {
|
|
113
|
+
expiresIn: "1h",
|
|
114
|
+
});
|
|
115
|
+
return res
|
|
116
|
+
.status(200)
|
|
117
|
+
.json({ message: "user logged in", token: token });
|
|
112
118
|
}
|
|
113
119
|
}
|
|
120
|
+
else {
|
|
121
|
+
return res
|
|
122
|
+
.status(401)
|
|
123
|
+
.json({ message: "user has not completed a captcha", verified });
|
|
124
|
+
}
|
|
114
125
|
}
|
|
126
|
+
return res.status(404).json({ message: "user not found" });
|
|
115
127
|
})
|
|
116
128
|
.catch((err) => {
|
|
117
|
-
console.error(
|
|
118
|
-
res.status(500).json({ message: err.message ||
|
|
129
|
+
console.error("error", err);
|
|
130
|
+
res.status(500).json({ message: err.message || "internal server error" });
|
|
119
131
|
});
|
|
120
132
|
};
|
|
121
133
|
const isAuth = (req, res) => {
|
|
122
|
-
const authHeader = req.get(
|
|
134
|
+
const authHeader = req.get("Authorization") || "";
|
|
123
135
|
if (!authHeader) {
|
|
124
|
-
res.status(401).json({ message:
|
|
136
|
+
res.status(401).json({ message: "not authenticated" });
|
|
125
137
|
}
|
|
126
|
-
const token = at(authHeader.split(
|
|
127
|
-
let decodedToken;
|
|
138
|
+
const token = at(authHeader.split(" "), 1);
|
|
139
|
+
let decodedToken = "";
|
|
128
140
|
try {
|
|
129
|
-
decodedToken = jwt.verify(token,
|
|
141
|
+
decodedToken = jwt.verify(token, "secret");
|
|
130
142
|
}
|
|
131
143
|
catch (err) {
|
|
132
|
-
res.status(500).json({
|
|
144
|
+
res.status(500).json({
|
|
145
|
+
message: err.message || "could not decode the token",
|
|
146
|
+
});
|
|
133
147
|
}
|
|
134
148
|
if (!decodedToken) {
|
|
135
|
-
res.status(401).json({ message:
|
|
149
|
+
res.status(401).json({ message: "unauthorized" });
|
|
136
150
|
}
|
|
137
151
|
else {
|
|
138
|
-
res.status(200).json({ message:
|
|
152
|
+
res.status(200).json({ message: "here is your resource" });
|
|
139
153
|
}
|
|
140
154
|
};
|
|
141
155
|
export { signup, login, isAuth };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAchD,OAAO,EACL,SAAS,GAGV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAEnC,OAAO,GAAwB,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,KAAK,CAChD,CAAC,CAAC,MAAM,CAAC;IACP,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE;IACzB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;CACrB,CAAC,CACH,CAAC;AAEF,SAAS,YAAY,CAAC,Q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B;SAChE,CAAC,CAAC;KACJ;IAED,IAAI,CAAC,YAAY,EAAE;QACjB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;KACnD;SAAM;QACL,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC,CAAC;KAC5D;AACH,CAAC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/models/user.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="mongoose/types/document" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="mongoose/types/types" resolution-mode="require"/>
|
|
3
|
+
/// <reference types="mongoose/types/models" resolution-mode="require"/>
|
|
4
|
+
/// <reference types="mongoose/types/schemaoptions" resolution-mode="require"/>
|
|
5
|
+
/// <reference types="mongoose/types/utility" resolution-mode="require"/>
|
|
6
|
+
import mongoose from "mongoose";
|
|
2
7
|
export interface UserInterface {
|
|
3
8
|
id: number;
|
|
4
9
|
email: string;
|
|
@@ -8,7 +13,7 @@ export interface UserInterface {
|
|
|
8
13
|
}
|
|
9
14
|
declare const UserSchema: mongoose.Schema<UserInterface, mongoose.Model<UserInterface, any, any, any, mongoose.Document<unknown, any, UserInterface> & UserInterface & {
|
|
10
15
|
_id: mongoose.Types.ObjectId;
|
|
11
|
-
}, any>, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, UserInterface, mongoose.Document<unknown, {}, UserInterface
|
|
16
|
+
}, any>, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, UserInterface, mongoose.Document<unknown, {}, mongoose.FlatRecord<UserInterface>> & mongoose.FlatRecord<UserInterface> & {
|
|
12
17
|
_id: mongoose.Types.ObjectId;
|
|
13
18
|
}>;
|
|
14
19
|
export default UserSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":"AAaA,OAAO,QAAoB,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":";;;;;AAaA,OAAO,QAAoB,MAAM,UAAU,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,QAAA,MAAM,UAAU;;;;EAmBd,CAAC;AAEH,eAAe,UAAU,CAAC"}
|
package/dist/models/user.js
CHANGED
package/dist/models/user.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":"AAaA,OAAO,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":"AAaA,OAAO,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAU5C,MAAM,UAAU,GAAG,IAAI,MAAM,CAAgB;IAC5C,KAAK,EAAE;QACN,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;QACjC,QAAQ,EAAE,IAAI;KACd;IACD,IAAI,EAAE;QACL,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;KACjC;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;QACjC,QAAQ,EAAE,IAAI;KACd;IACD,EAAE,EAAE;QACH,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;KACjC;IACD,IAAI,EAAE;QACL,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;QACjC,QAAQ,EAAE,IAAI;KACd;CACD,CAAC,CAAC;AAEH,eAAe,UAAU,CAAC"}
|
package/dist/routes/routes.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { ProsopoServerConfigOutput } from
|
|
3
|
-
import express from
|
|
1
|
+
/// <reference types="mongoose/types/connection" resolution-mode="require"/>
|
|
2
|
+
import type { ProsopoServerConfigOutput } from "@prosopo/types";
|
|
3
|
+
import express from "express";
|
|
4
|
+
import type { Connection } from "mongoose";
|
|
4
5
|
declare function getRoutes(mongoose: Connection, config: ProsopoServerConfigOutput, verifyEndpoint: string, verifyType: string): express.Router;
|
|
5
6
|
export default getRoutes;
|
|
6
7
|
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/routes/routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/routes/routes.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,OAAO,MAAM,SAAS,CAAC;AAc9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAK3C,iBAAS,SAAS,CACjB,QAAQ,EAAE,UAAU,EACpB,MAAM,EAAE,yBAAyB,EACjC,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAsBhB;AAED,eAAe,SAAS,CAAC"}
|
package/dist/routes/routes.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { isAuth, login, signup } from "../controllers/auth.js";
|
|
3
3
|
const router = express.Router();
|
|
4
4
|
function getRoutes(mongoose, config, verifyEndpoint, verifyType) {
|
|
5
|
-
router.post(
|
|
6
|
-
router.post(
|
|
7
|
-
router.get(
|
|
8
|
-
router.get(
|
|
9
|
-
res.status(200).json({ message:
|
|
5
|
+
router.post("/login", login.bind(null, mongoose, config, verifyEndpoint, verifyType));
|
|
6
|
+
router.post("/signup", signup.bind(null, mongoose, config, verifyEndpoint, verifyType));
|
|
7
|
+
router.get("/private", isAuth);
|
|
8
|
+
router.get("/public", (req, res) => {
|
|
9
|
+
res.status(200).json({ message: "here is your public resource" });
|
|
10
10
|
});
|
|
11
|
-
router.use(
|
|
12
|
-
res.status(404).json({ error:
|
|
11
|
+
router.use("/", (req, res) => {
|
|
12
|
+
res.status(404).json({ error: "page not found" });
|
|
13
13
|
});
|
|
14
14
|
return router;
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/routes/routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/routes/routes.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAe9B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAE/D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;AAEhC,SAAS,SAAS,CACjB,QAAoB,EACpB,MAAiC,EACjC,cAAsB,EACtB,UAAkB;IAElB,MAAM,CAAC,IAAI,CACV,QAAQ,EACR,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,CAAC,CAC9D,CAAC;IAEF,MAAM,CAAC,IAAI,CACV,SAAS,EACT,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,CAAC,CAC/D,CAAC;IAEF,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAE/B,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAClC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAGH,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC5B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AACf,CAAC;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="mongoose/types/connection" resolution-mode="require"/>
|
|
2
|
+
import { type Connection } from "mongoose";
|
|
2
3
|
declare function connectionFactory(uri: string): Connection;
|
|
3
4
|
export default connectionFactory;
|
|
4
5
|
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":";AAiBA,OAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAGrD,iBAAS,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CASlD;AACD,eAAe,iBAAiB,CAAC"}
|
package/dist/utils/connection.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { AutoIncrementID } from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { AutoIncrementID, } from "@typegoose/auto-increment";
|
|
2
|
+
import mongoose from "mongoose";
|
|
3
|
+
import UserSchema from "../models/user.js";
|
|
4
4
|
function connectionFactory(uri) {
|
|
5
5
|
const conn = mongoose.createConnection(uri);
|
|
6
6
|
if (!conn.models.user) {
|
|
7
|
-
UserSchema.plugin(AutoIncrementID, {
|
|
8
|
-
|
|
7
|
+
UserSchema.plugin(AutoIncrementID, {
|
|
8
|
+
field: "id",
|
|
9
|
+
});
|
|
10
|
+
conn.model("User", UserSchema);
|
|
9
11
|
}
|
|
10
12
|
return conn;
|
|
11
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAaA,OAAO,EACN,eAAe,GAEf,MAAM,2BAA2B,CAAC;AACnC,OAAO,QAA6B,MAAM,UAAU,CAAC;AACrD,OAAO,UAAU,MAAM,mBAAmB,CAAC;AAE3C,SAAS,iBAAiB,CAAC,GAAW;IACrC,MAAM,IAAI,GAAG,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;QACtB,UAAU,CAAC,MAAM,CAAC,eAAe,EAAE;YAClC,KAAK,EAAE,IAAI;SACe,CAAC,CAAC;QAC7B,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;KAC/B;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AACD,eAAe,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAcA,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAIzD;AACD,eAAe,iBAAiB,
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAcA,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAIzD;AACD,eAAe,iBAAiB,CAAC"}
|
package/dist/utils/database.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACtC,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,EAAE,CAAC;IAC1C,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC;IAClC,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC;AAC9B,CAAC;AACD,eAAe,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,60 +1,52 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"devDependencies": {
|
|
53
|
-
"@types/jsonwebtoken": "^9.0.2",
|
|
54
|
-
"nodemon": "^2.0.22",
|
|
55
|
-
"tslib": "2.6.2",
|
|
56
|
-
"typescript": "5.1.6",
|
|
57
|
-
"vite": "^5.1.7",
|
|
58
|
-
"@prosopo/config": "1.0.2"
|
|
59
|
-
}
|
|
2
|
+
"name": "@prosopo/client-example-server",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Backend for client-example",
|
|
5
|
+
"main": "dist/app.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20",
|
|
9
|
+
"npm": ">=9"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "echo \"No test specified\"",
|
|
13
|
+
"dev": "NODE_ENV=${NODE_ENV:-development}; vite serve --mode=$NODE_ENV --config ./vite.config.ts --host",
|
|
14
|
+
"start": "node ./dist/app.js",
|
|
15
|
+
"start:bundle": "node ./dist/bundle/prosopo_client_example_server.app.bundle.js",
|
|
16
|
+
"build": "tsc --build --verbose",
|
|
17
|
+
"bundle": "NODE_ENV=${NODE_ENV:-production}; vite build --mode=$NODE_ENV --config ./vite.config.ts",
|
|
18
|
+
"clean": "tsc --build --clean"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/prosopo/client-example-server.git"
|
|
23
|
+
},
|
|
24
|
+
"author": "PROSOPO LIMITED <info@prosopo.io>",
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/prosopo/client-example-server/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/prosopo/client-example-server#readme",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@noble/hashes": "^1.3.1",
|
|
32
|
+
"@polkadot/util": "12.6.2",
|
|
33
|
+
"@polkadot/util-crypto": "12.6.2",
|
|
34
|
+
"@prosopo/api": "2.0.1",
|
|
35
|
+
"@prosopo/contract": "2.0.1",
|
|
36
|
+
"@prosopo/procaptcha": "2.0.1",
|
|
37
|
+
"@prosopo/server": "2.0.1",
|
|
38
|
+
"@prosopo/types": "2.0.1",
|
|
39
|
+
"@typegoose/auto-increment": "^4.5.0",
|
|
40
|
+
"cors": "^2.8.5",
|
|
41
|
+
"jsonwebtoken": "^9.0.0",
|
|
42
|
+
"mongoose": "^8.5.1",
|
|
43
|
+
"zod": "^3.22.3"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@prosopo/config": "2.0.1",
|
|
47
|
+
"@types/jsonwebtoken": "^9.0.2",
|
|
48
|
+
"tslib": "2.6.2",
|
|
49
|
+
"typescript": "5.1.6",
|
|
50
|
+
"vite": "^5.1.7"
|
|
51
|
+
}
|
|
60
52
|
}
|
package/typedoc.config.js
CHANGED
|
@@ -12,8 +12,14 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
export default {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
entryPoints: [
|
|
16
|
+
"src/**/*.ts",
|
|
17
|
+
"src/**/*.tsx",
|
|
18
|
+
"src/**/*.js",
|
|
19
|
+
"src/**/*.jsx",
|
|
20
|
+
"src/**/*.json",
|
|
21
|
+
],
|
|
22
|
+
includes: "src",
|
|
23
|
+
extends: "../../typedoc.base.config.js",
|
|
24
|
+
readme: "README.md",
|
|
25
|
+
};
|
package/vite.config.ts
CHANGED
|
@@ -11,29 +11,37 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
import * as path from
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import { version } from
|
|
14
|
+
import * as path from "node:path";
|
|
15
|
+
import { loadEnv } from "@prosopo/cli";
|
|
16
|
+
import { ViteBackendConfig } from "@prosopo/config";
|
|
17
|
+
import { defineConfig } from "vite";
|
|
18
|
+
import { version } from "./package.json";
|
|
19
19
|
|
|
20
20
|
// load env using our util because vite loadEnv is not working for .env.development
|
|
21
|
-
loadEnv()
|
|
21
|
+
loadEnv();
|
|
22
22
|
|
|
23
23
|
// Package specific config
|
|
24
|
-
const packageName =
|
|
25
|
-
const packageVersion = version
|
|
26
|
-
const bundleName =
|
|
27
|
-
const dir = path.resolve()
|
|
28
|
-
const entry =
|
|
24
|
+
const packageName = "@prosopo/client-example-server";
|
|
25
|
+
const packageVersion = version;
|
|
26
|
+
const bundleName = "prosopo_client_example_server";
|
|
27
|
+
const dir = path.resolve();
|
|
28
|
+
const entry = "./src/app.ts";
|
|
29
29
|
|
|
30
|
-
process.env.TS_NODE_PROJECT = path.resolve(
|
|
30
|
+
process.env.TS_NODE_PROJECT = path.resolve("./tsconfig.json");
|
|
31
31
|
|
|
32
32
|
// Merge with generic backend config
|
|
33
33
|
export default defineConfig(async ({ command, mode }) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
const backendConfig = await ViteBackendConfig(
|
|
35
|
+
packageName,
|
|
36
|
+
packageVersion,
|
|
37
|
+
bundleName,
|
|
38
|
+
dir,
|
|
39
|
+
entry,
|
|
40
|
+
command,
|
|
41
|
+
mode,
|
|
42
|
+
);
|
|
43
|
+
return defineConfig({
|
|
44
|
+
...backendConfig,
|
|
45
|
+
server: { port: process.env.PROSOPO_SERVER_PORT },
|
|
46
|
+
});
|
|
47
|
+
});
|