@server/next 0.21.1 → 0.21.2
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/package.json +1 -1
- package/src/auth/auth.js +2 -2
- package/src/auth/index.js +2 -2
- package/src/auth/index.test.js +4 -2
- package/src/auth/logout.js +1 -1
- package/src/index.js +9 -9
- package/src/middle/index.js +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@server/next",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.2",
|
|
4
4
|
"description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
|
|
5
5
|
"homepage": "https://server-js.com/",
|
|
6
6
|
"repository": "https://github.com/franciscop/server-next.git",
|
package/src/auth/auth.js
CHANGED
|
@@ -48,8 +48,8 @@ export default async function auth(ctx) {
|
|
|
48
48
|
|
|
49
49
|
const auth = await options.session.get(sessionId);
|
|
50
50
|
// Mmh, which one to do...
|
|
51
|
-
if (!auth) throw ServerError.AUTH_NO_SESSION();
|
|
52
|
-
|
|
51
|
+
// if (!auth) throw ServerError.AUTH_NO_SESSION();
|
|
52
|
+
if (!auth) return; // SESSION ALREADY INVALID; no auth
|
|
53
53
|
|
|
54
54
|
if (!auth.provider) throw ServerError.AUTH_NO_PROVIDER();
|
|
55
55
|
if (!options.provider.includes(auth.provider)) {
|
package/src/auth/index.js
CHANGED
|
@@ -12,16 +12,16 @@ const load = async (ctx) => {
|
|
|
12
12
|
|
|
13
13
|
const middle = async (ctx) => {
|
|
14
14
|
if (ctx.options.auth) {
|
|
15
|
-
ctx.app.post("/auth/logout", logout);
|
|
16
|
-
|
|
17
15
|
if (ctx.options.auth.provider.includes("github")) {
|
|
18
16
|
if (!env.GITHUB_ID) throw new Error("GITHUB_ID not defined");
|
|
19
17
|
if (!env.GITHUB_SECRET) throw new Error("GITHUB_SECRET not defined");
|
|
18
|
+
ctx.app.get("/auth/logout", logout);
|
|
20
19
|
ctx.app.get("/auth/login/github", providers.github.login);
|
|
21
20
|
ctx.app.get("/auth/callback/github", providers.github.callback);
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
if (ctx.options.auth.provider.includes("email")) {
|
|
24
|
+
ctx.app.post("/auth/logout", logout);
|
|
25
25
|
ctx.app.post("/auth/register/email", providers.email.register);
|
|
26
26
|
ctx.app.post("/auth/login/email", providers.email.login);
|
|
27
27
|
ctx.app.put("/auth/password/email", providers.email.password);
|
package/src/auth/index.test.js
CHANGED
|
@@ -61,7 +61,8 @@ describe("token", () => {
|
|
|
61
61
|
it("cannot get the session", async () => {
|
|
62
62
|
const authorization = "Bearer REqA2l022l8Q0tuI";
|
|
63
63
|
const req = await api.get("/", { headers: { authorization } });
|
|
64
|
-
expect(req).
|
|
64
|
+
expect(req.status).toBe(404);
|
|
65
|
+
// expect(req).not.toSucceed("Invalid session");
|
|
65
66
|
});
|
|
66
67
|
|
|
67
68
|
it("cannot get the user", async () => {
|
|
@@ -112,7 +113,8 @@ describe("cookie", () => {
|
|
|
112
113
|
it("can get the proper session", async () => {
|
|
113
114
|
const cookie = "authentication=REqA2l022l8Q0tuI";
|
|
114
115
|
const req = await api.get("/", { headers: { cookie } });
|
|
115
|
-
expect(req).
|
|
116
|
+
expect(req.status).toBe(404);
|
|
117
|
+
// expect(req).not.toSucceed("Invalid session");
|
|
116
118
|
});
|
|
117
119
|
|
|
118
120
|
it("can get the proper session", async () => {
|
package/src/auth/logout.js
CHANGED
|
@@ -7,7 +7,7 @@ export default async function logout(ctx) {
|
|
|
7
7
|
if (type === "token") {
|
|
8
8
|
return { token: null };
|
|
9
9
|
} else if (type === "cookie") {
|
|
10
|
-
return cookies({ authorization: null }).
|
|
10
|
+
return cookies({ authorization: null }).redirect("/");
|
|
11
11
|
} else if (type === "jwt") {
|
|
12
12
|
throw new Error("JWT auth not supported yet");
|
|
13
13
|
} else if (type === "key") {
|
package/src/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
parseHeaders,
|
|
12
12
|
} from "./helpers/index.js";
|
|
13
13
|
|
|
14
|
-
import
|
|
14
|
+
import { assets, auth } from "./middle/index.js";
|
|
15
15
|
|
|
16
16
|
// Export the reply helpers
|
|
17
17
|
export * from "./reply.js";
|
|
@@ -29,7 +29,7 @@ export default function server(options = {}) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// Keep a copy of the options in the instance
|
|
32
|
-
this.opts = options;
|
|
32
|
+
this.opts = config(options);
|
|
33
33
|
this.platform = getMachine();
|
|
34
34
|
|
|
35
35
|
// TODO: find a way to remove this hack
|
|
@@ -74,7 +74,10 @@ export default function server(options = {}) {
|
|
|
74
74
|
this.node();
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
this.use(
|
|
77
|
+
this.use(assets);
|
|
78
|
+
if (this.opts.auth) {
|
|
79
|
+
this.use(auth({ options: this.opts, app: this }));
|
|
80
|
+
}
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
server.prototype.self = function () {
|
|
@@ -93,12 +96,11 @@ server.prototype.self = function () {
|
|
|
93
96
|
// #region Runtimes
|
|
94
97
|
// Node.js
|
|
95
98
|
server.prototype.node = async function () {
|
|
96
|
-
const options = config(this.opts);
|
|
97
99
|
const http = await import("http");
|
|
98
100
|
http
|
|
99
101
|
.createServer(async (request, response) => {
|
|
100
102
|
try {
|
|
101
|
-
const ctx = await createNodeContext(request,
|
|
103
|
+
const ctx = await createNodeContext(request, this.opts, this);
|
|
102
104
|
const out = await handleRequest(this.handlers, ctx);
|
|
103
105
|
|
|
104
106
|
response.writeHead(out.status || 200, parseHeaders(out.headers));
|
|
@@ -125,8 +127,7 @@ server.prototype.callback = async function (request, context) {
|
|
|
125
127
|
if (typeof Netlify === "undefined") {
|
|
126
128
|
throw new Error("Netlify doesn't exist");
|
|
127
129
|
}
|
|
128
|
-
const
|
|
129
|
-
const ctx = await createWinterContext(request, options, this);
|
|
130
|
+
const ctx = await createWinterContext(request, this.opts, this);
|
|
130
131
|
return await handleRequest(this.handlers, ctx);
|
|
131
132
|
} catch (error) {
|
|
132
133
|
return new Response(error.message, { status: error.status || 500 });
|
|
@@ -139,8 +140,7 @@ server.prototype.fetch = async function (request, env) {
|
|
|
139
140
|
Object.assign(globalThis.env, env); // Extend env with the passed vars
|
|
140
141
|
|
|
141
142
|
try {
|
|
142
|
-
const
|
|
143
|
-
const ctx = await createWinterContext(request, options, this);
|
|
143
|
+
const ctx = await createWinterContext(request, this.opts, this);
|
|
144
144
|
return await handleRequest(this.handlers, ctx);
|
|
145
145
|
} catch (error) {
|
|
146
146
|
return new Response(error.message, { status: error.status || 500 });
|
package/src/middle/index.js
CHANGED