This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AccountStore = require('../stores/account.store'); | |
class AccountController { | |
static async register(req, res) { | |
try { | |
let payload = await AccountStore.register(req); | |
res.send(payload); | |
} catch(exception) { | |
res.status(500).send(exception) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const AccountCtrl = require('../controllers/account.controller'); | |
const unauth = express.Router(); | |
unauth | |
.post('/account/register', AccountCtrl.register) | |
.post('/account/login', AccountCtrl.login) | |
module.exports = unauth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const AccountCtrl = require('../controllers/account.controller'); | |
const auth = express.Router(); | |
auth | |
.get('/account/self', AccountCtrl.self) | |
.put('/account/:_id', AccountCtrl.update) | |
.delete('/account/:_id', AccountCtrl.remove) | |
module.exports = auth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const moment = require('moment'); | |
class AuthenticationStore { | |
static async authenticate(req, res, next) { | |
const payload = await AuthenticationStore.consumeToken(req); | |
if (payload.status && payload.status !== 200) { | |
return res.status(payload.status).send(payload.message); | |
} | |
req.user = payload.sub; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AuthStore = require('../stores/authentication.store'); | |
module.exports = function(app) { | |
app.use('/api/v1', require('./routes.unauth')); | |
app.use('/api/v1', [AuthStore.authenticate], require('./routes.auth')); | |
app.use('/api/v1/admin', [AuthStore.authenticate, AuthStore.isAdmin], require('./routes.admin')); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
// other libs and middleware | |
const app = express(); | |
// pass the instance of our app to the routes. | |
require('./routes/routes.index.js')(app); | |
app.listen(5050); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const strToEval = '/hello' | |
const eval = (arg) => { | |
switch(arg.charAt(0)) { | |
case '\'': | |
// handle single quote | |
break; | |
case ' ': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config(); | |
const request = require('request-promise'); | |
// Hoist our users array. | |
let users = []; | |
const API_ENDPOINT = `https://publicapi.knowledgeanywhere.com`; | |
const CLIENT_ID = process.env.LMS_CLIENT_ID; // Loaded from our .env file | |
const CLIENT_SECRET = process.env.LMS_CLIENT_SECRET; // Loaded from our .env file | |
const PAGE_SIZE = 1000; // How many records the API returns in a page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ApiKey = require('../../lib/models/api-key.model'); | |
// Bootstrap default AO | |
ApiKey.findOneAndUpdate({ | |
origin: 'https://localhost:4200' | |
}, { | |
$set: { | |
// This is our default allowed origin, typically where your front-end is served from, ie myapp.com. In this case we use Angular's default serve port. | |
origin: 'https://localhost:4200' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = new Express(); | |
const cache = require('origin-cache'); | |
require('api-keys.script'); | |
const allowedOrigins = cache.get(); | |
// see full example: https://github.com/TaylorAckley/cors-app/blob/main/api/index.js | |
/** Use CORS. If RESTRICT_ORIGINS is enabled, only certain domains can call the API. **/ |