api: More configurable options
This commit is contained in:
parent
ccd3d80bae
commit
470dfe339d
|
@ -1,5 +1,11 @@
|
||||||
{
|
{
|
||||||
"cookieSecret": "CHANGEME!!!!!!!!!!@##@!!$$$$$$$$$$$$$!!",
|
"cookieSecret": "CHANGEME!!!!!!!!!!@##@!!$$$$$$$$$$$$$!!",
|
||||||
"jwtSecret": "CHANGEME??????????????////3212321;312kjbkasjd",
|
"jwtSecret": "CHANGEME??????????????////3212321;312kjbkasjd",
|
||||||
"mail": false
|
"baseUrl": "http://localhost:3000/",
|
||||||
|
"mainFrontendUrl": "http://localhost:3001/",
|
||||||
|
"mail": false,
|
||||||
|
"mongodb": {
|
||||||
|
"url": "mongodb://mongo/obsTest",
|
||||||
|
"debug": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"cookieSecret": "CHANGEME!!!!!!!!!!!!!!!!!!!!!11",
|
"cookieSecret": "CHANGEME!!!!!!!!!!!!!!!!!!!!!11",
|
||||||
"jwtSecret": "CHANGEME???????????????????////",
|
"jwtSecret": "CHANGEME???????????????????////",
|
||||||
|
"baseUrl": "https://openbikesensor.example.com/",
|
||||||
|
"mainFrontendUrl": "https://openbikesensor.example.com/api/",
|
||||||
"mail": {
|
"mail": {
|
||||||
"from": "Sender Name <sender@example.com>",
|
"from": "Sender Name <sender@example.com>",
|
||||||
"smtp" : {
|
"smtp" : {
|
||||||
|
@ -9,5 +11,9 @@
|
||||||
"username": "sender@example.com",
|
"username": "sender@example.com",
|
||||||
"password": "hunter2"
|
"password": "hunter2"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"mongodb": {
|
||||||
|
"url": "mongodb://user:pass@host/obs",
|
||||||
|
"debug": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,31 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const Joi = require('joi');
|
const Joi = require('joi');
|
||||||
|
|
||||||
const configSchema = Joi.object()
|
const configSchema = Joi.object({
|
||||||
.required()
|
|
||||||
.keys({
|
|
||||||
jwtSecret: Joi.string().min(16).max(128).required(),
|
jwtSecret: Joi.string().min(16).max(128).required(),
|
||||||
cookieSecret: Joi.string().min(16).max(128).required(),
|
cookieSecret: Joi.string().min(16).max(128).required(),
|
||||||
|
|
||||||
|
baseUrl: Joi.string().required(),
|
||||||
|
mainFrontendUrl: Joi.string(), // optional
|
||||||
|
|
||||||
mail: Joi.alternatives().try(
|
mail: Joi.alternatives().try(
|
||||||
Joi.object({
|
Joi.object({
|
||||||
from: Joi.string().required(),
|
from: Joi.string().required(),
|
||||||
smtp: Joi.object().required().keys({
|
smtp: Joi.object({
|
||||||
host: Joi.string().required(),
|
host: Joi.string().required(),
|
||||||
port: Joi.number().default(587),
|
port: Joi.number().default(587),
|
||||||
username: Joi.string().required(),
|
username: Joi.string().required(),
|
||||||
password: Joi.string().required(),
|
password: Joi.string().required(),
|
||||||
}),
|
}).required(),
|
||||||
}),
|
}),
|
||||||
Joi.boolean().valid(false),
|
Joi.boolean().valid(false),
|
||||||
),
|
),
|
||||||
});
|
|
||||||
|
mongodb: Joi.object({
|
||||||
|
url: Joi.string().required(),
|
||||||
|
debug: Joi.boolean().default(process.env.NODE_ENV !== 'production'),
|
||||||
|
}).required(),
|
||||||
|
}).required();
|
||||||
|
|
||||||
const configFiles = [
|
const configFiles = [
|
||||||
process.env.CONFIG_FILE,
|
process.env.CONFIG_FILE,
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
|
|
||||||
const isProduction = process.env.NODE_ENV === 'production';
|
const config = require('./config')
|
||||||
const mongodbUrl =
|
|
||||||
process.env.MONGODB_URL || (isProduction ? 'mongodb://localhost/obs' : 'mongodb://localhost/obsTest');
|
mongoose.connect(config.mongodb.url);
|
||||||
mongoose.connect(mongodbUrl);
|
mongoose.set('debug', config.mongodb.debug);
|
||||||
mongoose.set('debug', !isProduction);
|
|
||||||
|
|
||||||
require('./models/TrackData');
|
require('./models/TrackData');
|
||||||
require('./models/User');
|
require('./models/User');
|
||||||
|
|
|
@ -6,6 +6,7 @@ const { createChallenge } = require('pkce');
|
||||||
const { AuthorizationCode, AccessToken, RefreshToken, Client } = require('../models');
|
const { AuthorizationCode, AccessToken, RefreshToken, Client } = require('../models');
|
||||||
const auth = require('../passport');
|
const auth = require('../passport');
|
||||||
const wrapRoute = require('../_helpers/wrapRoute');
|
const wrapRoute = require('../_helpers/wrapRoute');
|
||||||
|
const config = require('../config')
|
||||||
|
|
||||||
// Check whether the "bigScope" fully includes the "smallScope".
|
// Check whether the "bigScope" fully includes the "smallScope".
|
||||||
function scopeIncludes(smallScope, bigScope) {
|
function scopeIncludes(smallScope, bigScope) {
|
||||||
|
@ -48,6 +49,7 @@ function isValidScope(scope) {
|
||||||
|
|
||||||
router.use((req, res, next) => {
|
router.use((req, res, next) => {
|
||||||
res.locals.user = req.user;
|
res.locals.user = req.user;
|
||||||
|
res.locals.mainFrontendUrl = config.mainFrontendUrl
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -397,7 +399,7 @@ router.get(
|
||||||
router.get(
|
router.get(
|
||||||
'/.well-known/oauth-authorization-server',
|
'/.well-known/oauth-authorization-server',
|
||||||
wrapRoute(async (req, res) => {
|
wrapRoute(async (req, res) => {
|
||||||
const baseUrl = 'http://localhost:3000';
|
const baseUrl = config.baseUrl.replace(/\/+$/, '')
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
issuer: baseUrl,
|
issuer: baseUrl,
|
||||||
|
|
|
@ -130,7 +130,8 @@ html
|
||||||
nav
|
nav
|
||||||
header OpenBikeSensor Account Pages
|
header OpenBikeSensor Account Pages
|
||||||
ul
|
ul
|
||||||
li: a(href="/") Back to Portal
|
if mainFrontendUrl
|
||||||
|
li: a(href=mainFrontendUrl) Back to Portal
|
||||||
if !user
|
if !user
|
||||||
li: a(href="/login") Login
|
li: a(href="/login") Login
|
||||||
li: a(href="/register") Register
|
li: a(href="/register") Register
|
||||||
|
|
Loading…
Reference in a new issue