-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modernize API: Update Node.js & deps, ESM, & more
- Loading branch information
Showing
67 changed files
with
9,197 additions
and
7,762 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
NODE_ENV=development | ||
|
||
BUGSNAG_API_KEY= | ||
DATABASE_URL=postgres://postgres:password@localhost:5432/piratepx_development | ||
PORT=3000 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
14 | ||
22 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 piratepx | ||
Copyright (c) 2024 piratepx | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
const path = require('path') | ||
import { join } from 'node:path' | ||
|
||
const AutoLoad = require('fastify-autoload') | ||
import autoLoad from '@fastify/autoload' | ||
|
||
const initializers = require('./initializers') | ||
import initializers from '#api/initializers/index' | ||
|
||
require('@/services/bugsnag') | ||
import { apiDir } from '#api/lib/paths' | ||
import cronJobScheduler from '#api/services/cron_job_scheduler' | ||
import errorHandler, { errorSchema } from '#api/services/errors/error_handler' | ||
|
||
const errorHandler = require('@/plugins/error_handler') | ||
const scheduleCronJobs = require('@/services/schedule_cron_jobs') | ||
|
||
module.exports = async (fastify, opts) => { | ||
// eslint-disable-next-line no-unused-vars | ||
async function app(fastify, options) { | ||
await initializers() | ||
|
||
fastify.register(AutoLoad, { | ||
dir: path.join(__dirname, 'plugins', 'common'), | ||
options: { ...opts }, | ||
}) | ||
fastify.addSchema(errorSchema) | ||
fastify.setErrorHandler(errorHandler) | ||
|
||
fastify.register(AutoLoad, { | ||
dir: path.join(__dirname, 'routes'), | ||
options: { ...opts }, | ||
await fastify.register(autoLoad, { | ||
dir: join(apiDir, 'plugins'), | ||
encapsulate: false, | ||
}) | ||
|
||
fastify.setErrorHandler(errorHandler) | ||
fastify.register(autoLoad, { | ||
dir: join(apiDir, 'routes'), | ||
autoHooks: true, | ||
cascadeHooks: true, | ||
routeParams: true, | ||
}) | ||
|
||
scheduleCronJobs() | ||
cronJobScheduler() | ||
} | ||
|
||
export default app |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
const Knex = require('knex') | ||
import Knex from 'knex' | ||
import { env } from 'node:process' | ||
|
||
const config = require('@/db/config') | ||
import config from '#api/db/config' | ||
|
||
module.exports = Knex(config[process.env.NODE_ENV]) | ||
const db = Knex(config[env.NODE_ENV]) | ||
|
||
export default db |
10 changes: 8 additions & 2 deletions
10
api/db/migrations/20200713072454_create_uuid_ossp_extension.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
exports.up = (knex) => knex.raw('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"') | ||
async function up(knex) { | ||
return await knex.raw('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"') | ||
} | ||
|
||
exports.down = (knex) => knex.raw('DROP EXTENSION IF EXISTS "uuid-ossp"') | ||
async function down(knex) { | ||
return await knex.raw('DROP EXTENSION IF EXISTS "uuid-ossp"') | ||
} | ||
|
||
export { up, down } |
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
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
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
12 changes: 8 additions & 4 deletions
12
api/db/migrations/20201007055505_add_shared_secret_to_projects.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
exports.up = (knex) => | ||
knex.schema.table('projects', (t) => { | ||
async function up(knex) { | ||
return await knex.schema.table('projects', (t) => { | ||
t.string('shared_secret').unique() | ||
}) | ||
} | ||
|
||
exports.down = (knex) => | ||
knex.schema.table('projects', (t) => { | ||
async function down(knex) { | ||
return await knex.schema.table('projects', (t) => { | ||
t.dropColumn('shared_secret') | ||
}) | ||
} | ||
|
||
export { up, down } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
require('dotenv').config() | ||
require('module-alias/register') | ||
import 'dotenv/config' | ||
|
||
const objection = require('@/initializers/objection') | ||
const pg = require('@/initializers/pg') | ||
import initializeObjection from '#api/initializers/objection' | ||
import initializePG from '#api/initializers/pg' | ||
|
||
module.exports = async () => { | ||
pg() | ||
await objection() | ||
async function initializers() { | ||
initializePG() | ||
await initializeObjection() | ||
} | ||
|
||
export default initializers |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
const { Model } = require('objection') | ||
import { Model } from 'objection' | ||
|
||
const db = require('@/db') | ||
import db from '#api/db/index' | ||
|
||
module.exports = () => { | ||
async function initializeObjection() { | ||
Model.knex(db) | ||
|
||
return db.raw("SELECT 'Hello?'") | ||
await db.raw("SELECT 'Hello?'") | ||
} | ||
|
||
export default initializeObjection |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const { types } = require('pg') | ||
import pg from 'pg' | ||
|
||
module.exports = () => { | ||
function initializePG() { | ||
// Parse date type as string instead of Date to prevent time zone conversion. | ||
// See: https://github.com/brianc/node-postgres/issues/1844 | ||
types.setTypeParser(1082, (date) => date) | ||
pg.types.setTypeParser(1082, (date) => date) | ||
} | ||
|
||
export default initializePG |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { dirname, join } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
const rootDir = join(dirname(fileURLToPath(import.meta.url)), '..', '..') | ||
const apiDir = join(rootDir, 'api') | ||
const webDir = join(rootDir, 'web') | ||
|
||
export { rootDir, apiDir, webDir } |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
module.exports = Buffer.from( | ||
import { Buffer } from 'buffer' | ||
|
||
const px = Buffer.from( | ||
'R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==', | ||
'base64' | ||
'base64', | ||
) | ||
|
||
export default px |
Oops, something went wrong.