Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ DB_HOST=
DB_USER=
DB_PASS=
DB_NAME=
DB_TEST_NAME=

ALGOLIA_APP_ID=
ALGOLIA_APP_SECRET=
Expand All @@ -10,4 +11,4 @@ GOOGLE_MAP_KEY=

NODE_ENV=development

API_KEYS=
API_KEYS=
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ app.use(router.routes());
app.use(router.allowedMethods());

const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`App running on http://localhost:${port}`));
module.exports = app.listen(port, () => console.log(`App running on http://localhost:${port}`));
2 changes: 1 addition & 1 deletion controllers/LocationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports = {
if (!location.id) {
return ctx.abortJson({}, `Location with ID: ${id} does not exist`);
}
await location.delete();
await location.destroy();
ctx.sendJson(location, `Location with ID: ${id} deleted`);
} catch (error) {
ctx.abortJson(error, `Error deleting location with ID: ${id}`);
Expand Down
19 changes: 19 additions & 0 deletions knexfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Update with your config settings.
require('dotenv').config();

module.exports = {
development: {
Expand All @@ -19,6 +20,24 @@ module.exports = {
}
},

test: {
client: 'mysql',
debug: false,
connection: {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_TEST_NAME,
port: process.env.DB_PORT
},
migrations: {
directory: './db/migrations'
},
seeds: {
directory: './db/seeds'
}
},

staging: {
client: 'mysql',
debug: false,
Expand Down
3 changes: 2 additions & 1 deletion middleware/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ const Router = require('koa-router');
const searchController = require('../controllers/SearchController');
const locationController = require('../controllers/LocationController');

require('dotenv').config();
const router = new Router();

// @todo
// temporary hack
// check if permitted request
const { API_KEYS } = process.env;
const allowedKeys = API_KEYS ? API_KEYS.split(',') : [];
router.use(async (ctx, next) => {
router.use(async function (ctx, next) {
const { key } = ctx.query;
if (!allowedKeys.includes(key)) {
const error = 'Invalid API key';
Expand Down
Loading