chore(project) cleanup
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { LayServer } from '../src';
|
||||
import { LayServer } from '../lib';
|
||||
import { google } from 'googleapis';
|
||||
|
||||
class InfoController {
|
||||
static namespace = 'info';
|
||||
@@ -27,6 +28,44 @@ class InfoController {
|
||||
}
|
||||
}
|
||||
|
||||
class oAuthController {
|
||||
static namespace = 'oauth';
|
||||
constructor(server) {
|
||||
server.get('/:provider', this.auth.bind(this));
|
||||
server.get('/callback/:provider', this.callback.bind(this));
|
||||
}
|
||||
|
||||
async auth(req, res) {
|
||||
if (req.params.get('provider') != 'google') {
|
||||
return {
|
||||
messages: 'invalid provider',
|
||||
data: [...req.params.entries()],
|
||||
};
|
||||
}
|
||||
|
||||
const scopes = 'https://www.googleapis.com/auth/youtube';
|
||||
const url = oauth2Client.generateAuthUrl({
|
||||
// 'online' (default) or 'offline' (gets refresh_token)
|
||||
access_type: 'offline',
|
||||
|
||||
// If you only need one scope you can pass it as a string
|
||||
scope: scopes,
|
||||
});
|
||||
|
||||
console.log(url);
|
||||
|
||||
return Response.redirect(url, 301);
|
||||
}
|
||||
|
||||
callback(req, res) {
|
||||
if (!req.query.get('code')) {
|
||||
return new Response('/', { status: 302 });
|
||||
}
|
||||
|
||||
return new Response(`/${req.query.get('code')}`);
|
||||
}
|
||||
}
|
||||
|
||||
const server = new LayServer({
|
||||
controllers: [
|
||||
function Main(server) {
|
||||
@@ -71,8 +110,9 @@ const server = new LayServer({
|
||||
});
|
||||
});
|
||||
},
|
||||
oAuthController,
|
||||
InfoController,
|
||||
],
|
||||
});
|
||||
|
||||
server.listen(42069);
|
||||
server.listen(Bun.env.APP_PORT ?? Bun.env.PORT ?? 42169);
|
||||
|
||||
Reference in New Issue
Block a user