-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30e7ad1
commit 5a2b187
Showing
12 changed files
with
200 additions
and
23 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 |
---|---|---|
|
@@ -35,6 +35,8 @@ jobs: | |
- uses: bahmutov/npm-install@v1 | ||
- name: Publish app | ||
uses: cloudflare/[email protected] | ||
env: | ||
SENTRY_TOKEN: ${{secrets.SENTRY_TOKEN}} | ||
with: | ||
apiToken: ${{secrets.CF_API_TOKEN }} | ||
workingDirectory: 'packages/gateway' | ||
|
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 |
---|---|---|
|
@@ -120,6 +120,9 @@ jobs: | |
- name: Gateway - Deploy | ||
if: ${{ steps.tag-release.outputs.release_created && matrix.package == 'gateway' }} | ||
uses: cloudflare/[email protected] | ||
env: | ||
SENTRY_TOKEN: ${{ secrets.SENTRY_TOKEN }} | ||
SENTRY_UPLOAD: ${{ secrets.SENTRY_UPLOAD }} | ||
with: | ||
apiToken: ${{ secrets.CF_API_TOKEN }} | ||
workingDirectory: 'packages/gateway' | ||
|
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
nonSemVerExperiments: { | ||
configurableModuleFormat: true, | ||
}, | ||
files: ['test/*.spec.js'], | ||
timeout: '5m', | ||
nodeArguments: ['--experimental-vm-modules'], | ||
} |
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 |
---|---|---|
|
@@ -4,9 +4,9 @@ | |
"description": "IPFS gateway for nft.storage", | ||
"private": true, | ||
"type": "module", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"scripts": { | ||
"build": "esbuild --bundle --sourcemap --outdir=dist ./src/index.js", | ||
"build": "node scripts/cli.js build", | ||
"dev": "miniflare --watch --debug", | ||
"deploy": "wrangler publish --env production", | ||
"pretest": "npm run build ", | ||
|
@@ -15,14 +15,19 @@ | |
"mock:ipfs.io": "smoke -p 9081 test/mocks/ipfs.io" | ||
}, | ||
"dependencies": { | ||
"multiformats": "^9.5.2" | ||
"multiformats": "^9.5.2", | ||
"toucan-js": "^2.4.1" | ||
}, | ||
"devDependencies": { | ||
"@sentry/cli": "^1.71.0", | ||
"ava": "^3.15.0", | ||
"esbuild": "^0.14.2", | ||
"git-rev-sync": "^3.0.1", | ||
"miniflare": "^2.0.0-rc.2", | ||
"npm-run-all": "^4.1.5", | ||
"smoke": "^3.1.1" | ||
"sade": "^1.7.4", | ||
"smoke": "^3.1.1", | ||
"toucan-js": "^2.5.0" | ||
}, | ||
"author": "Vasco Santos <[email protected]>", | ||
"license": "(Apache-2.0 AND MIT)" | ||
|
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,74 @@ | ||
#!/usr/bin/env node | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { fileURLToPath } from 'url' | ||
import sade from 'sade' | ||
import { build } from 'esbuild' | ||
import git from 'git-rev-sync' | ||
import Sentry from '@sentry/cli' | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
const pkg = JSON.parse( | ||
fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8') | ||
) | ||
|
||
const prog = sade('gateway') | ||
|
||
prog | ||
.command('build') | ||
.describe('Build the worker.') | ||
.option('--env', 'Environment', 'dev') | ||
.action(async (opts) => { | ||
try { | ||
const version = `${pkg.name}@${pkg.version}-${opts.env}+${git.short( | ||
__dirname | ||
)}` | ||
|
||
await build({ | ||
entryPoints: [path.join(__dirname, '../src/index.js')], | ||
bundle: true, | ||
format: 'esm', | ||
outfile: 'dist/index.mjs', | ||
legalComments: 'external', | ||
define: { | ||
VERSION: JSON.stringify(version), | ||
COMMITHASH: JSON.stringify(git.long(__dirname)), | ||
BRANCH: JSON.stringify(git.branch(__dirname)), | ||
ENV: opts.env || 'dev', | ||
global: 'globalThis', | ||
}, | ||
minify: opts.env === 'dev' ? false : true, | ||
sourcemap: true, | ||
}) | ||
|
||
// Sentry release and sourcemap upload | ||
if (process.env.SENTRY_UPLOAD === 'true') { | ||
const cli = new Sentry(undefined, { | ||
authToken: process.env.SENTRY_TOKEN, | ||
org: 'protocol-labs-it', | ||
project: 'nft-gateway', | ||
dist: git.short(__dirname), | ||
}) | ||
|
||
await cli.releases.new(version) | ||
await cli.releases.setCommits(version, { | ||
auto: true, | ||
ignoreEmpty: true, | ||
ignoreMissing: true, | ||
}) | ||
await cli.releases.uploadSourceMaps(version, { | ||
include: ['./dist'], | ||
urlPrefix: '/', | ||
}) | ||
await cli.releases.finalize(version) | ||
await cli.releases.newDeploy(version, { | ||
env: opts.env, | ||
}) | ||
} | ||
} catch (err) { | ||
console.error(err) | ||
process.exit(1) | ||
} | ||
}) | ||
|
||
prog.parse(process.argv) |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export class InvalidIpfsPathError extends Error { | ||
/** | ||
* @param {string} cid | ||
*/ | ||
constructor(cid) { | ||
super(`invalid ipfs path: invalid path "/ipfs/${cid}/"`) | ||
this.name = 'InvalidIpfsPath' | ||
this.status = 400 | ||
this.code = InvalidIpfsPathError.CODE | ||
} | ||
} | ||
InvalidIpfsPathError.CODE = 'ERROR_INVALID_IPFS_PATH' | ||
|
||
export class InvalidUrlError extends Error { | ||
/** | ||
* @param {string} url | ||
*/ | ||
constructor(url) { | ||
super(`invalid url: ${url}`) | ||
this.name = 'InvalidUrl' | ||
this.status = 400 | ||
this.code = InvalidUrlError.CODE | ||
} | ||
} | ||
InvalidUrlError.CODE = 'ERROR_INVALID_URL' |
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
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