Skip to content

Commit ae70a2f

Browse files
authored
Merge pull request #38 from oslabs-beta/staging-faast
Project Management by Aaron and Server Separation by Andrew
2 parents fea6749 + b7ffaa6 commit ae70a2f

31 files changed

+834
-689
lines changed

app/electron/main.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async function createWindow() {
6161
webPreferences: {
6262
zoomFactor: 0.7,
6363
// enable devtools
64-
devTools: isDev,
64+
devTools: true,
6565
// crucial security feature - blocks rendering process from having access to node moduels
6666
nodeIntegration: false,
6767
// web workers will not have access to node
@@ -133,6 +133,7 @@ async function createWindow() {
133133
// TODO: is this the same type of sessions that have in react type
134134
// Could potentially remove this session capability - it appears to be more focused on approving requests from 3rd party notifications
135135
const ses = session;
136+
136137
const partition = 'default';
137138
ses
138139
.fromPartition(partition)
@@ -177,7 +178,9 @@ protocol.registerSchemesAsPrivileged([
177178
scheme: Protocol.scheme,
178179
privileges: {
179180
standard: true,
180-
secure: true
181+
secure: true,
182+
allowServiceWorkers: true,
183+
supportFetchAPI: true
181184
}
182185
}
183186
]);
@@ -219,13 +222,13 @@ app.on('web-contents-created', (event, contents) => {
219222
const parsedUrl = new URL(navigationUrl);
220223
const validOrigins = [
221224
selfHost,
222-
'https://localhost:8080',
225+
'https://localhost:8081',
223226
'https://github.com/'
224227
];
225228
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
226229
if (!validOrigins.includes(parsedUrl.origin)) {
227230
console.error(
228-
`The application tried to redirect to the following address: '${parsedUrl}'. This origin is not whitelisted and the attempt to navigate was blocked.`
231+
`The application tried to navigate to the following address: '${parsedUrl}'. This origin is not whitelisted and the attempt to navigate was blocked.`
229232
);
230233
// if the requested URL is not in the whitelisted array, then don't navigate there
231234
event.preventDefault();
@@ -235,14 +238,20 @@ app.on('web-contents-created', (event, contents) => {
235238

236239
contents.on('will-redirect', (event, navigationUrl) => {
237240
const parsedUrl = new URL(navigationUrl);
241+
//console.log('parsedUrl is', parsedUrl);
242+
//console.log('parsedUrl.origin is', parsedUrl.origin);
238243
const validOrigins = [
239244
selfHost,
240-
'https://localhost:8080',
241-
'https://github.com/'
245+
'https://localhost:8081',
246+
'https://github.com',
247+
'app://rse/'
242248
];
243249

244250
// Log and prevent the app from redirecting to a new page
245-
if (!validOrigins.includes(parsedUrl.origin)) {
251+
if (
252+
!validOrigins.includes(parsedUrl.origin) &&
253+
!validOrigins.includes(parsedUrl.href)
254+
) {
246255
console.error(
247256
`The application tried to redirect to the following address: '${navigationUrl}'. This attempt was blocked.`
248257
);
@@ -318,3 +327,29 @@ ipcMain.on('choose_app_dir', event => {
318327
})
319328
.catch(err => console.log('ERROR on "choose_app_dir" event: ', err));
320329
});
330+
331+
// for github oauth login in production, since cookies are not accessible through document.cookie on local filesystem, we need electron to grab the cookie that is set from oauth, this listens for an set cookie event from the renderer process then sends back the cookie
332+
ipcMain.on('set_cookie', event => {
333+
session.defaultSession.cookies
334+
.get({ url: 'https://localhost:8081' })
335+
.then(cookie => {
336+
console.log(cookie);
337+
event.reply('give_cookie', cookie);
338+
})
339+
.catch(error => {
340+
console.log('Error giving cookies in set_cookie:', error);
341+
});
342+
});
343+
344+
// again for production, document.cookie is not accessible so we need this listener on main to delete the cookie on logout
345+
ipcMain.on('delete_cookie', event => {
346+
session.defaultSession.cookies
347+
.remove('https://localhost:8081', 'ssid')
348+
.then(removed => {
349+
console.log('Cookies deleted', removed);
350+
})
351+
.catch(err => console.log('Error deleting cookie:', err));
352+
});
353+
354+
// bypass ssl certification validation error
355+
// app.commandLine.appendSwitch('ignore-certificate-errors', 'true');

app/electron/preload.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ const {
88
addAppDirChosenListener,
99
removeAllAppDirChosenListeners
1010
} = require('./preloadFunctions/chooseAppDir');
11+
const {
12+
setCookie,
13+
getCookie,
14+
delCookie,
15+
reload
16+
} = require('./preloadFunctions/cookies');
1117

1218
// Expose protected methods that allow the renderer process to use
1319
// the ipcRenderer without exposing the entire object
@@ -25,5 +31,8 @@ contextBridge.exposeInMainWorld('api', {
2531
existsSync: existsSync,
2632
writeFileSync: writeFileSync,
2733
mkdirSync: mkdirSync,
28-
writeFile: writeFile
34+
writeFile: writeFile,
35+
setCookie: setCookie,
36+
getCookie: getCookie,
37+
delCookie: delCookie
2938
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { ipcRenderer } = require('electron');
2+
3+
const setCookie = () => {
4+
return ipcRenderer.send('set_cookie');
5+
};
6+
7+
const getCookie = callback => {
8+
return ipcRenderer.on('give_cookie', (event, cookie) => {
9+
callback(cookie);
10+
});
11+
};
12+
13+
const delCookie = () => {
14+
return ipcRenderer.send('delete_cookie');
15+
};
16+
17+
module.exports = { setCookie, getCookie, delCookie };

app/server/controllers/cookieController.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/server/controllers/projectController.js

Lines changed: 0 additions & 59 deletions
This file was deleted.

app/server/controllers/sessionController.js

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)