Skip to content

Commit

Permalink
feat: init node API
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Apr 8, 2023
1 parent ce474fe commit 79b7132
Show file tree
Hide file tree
Showing 9 changed files with 2,834 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab
indent_size = 4
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
.DS_Store
node_modules
.vscode
.next
out
build

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
209 changes: 209 additions & 0 deletions _config/nodeAPI/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
module.exports = {
'env': {
'node': true,
'browser': true,
'es2021': true
},
'extends': [
'eslint:recommended',
'plugin:import/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:tailwindcss/recommended',
'plugin:@typescript-eslint/recommended',
'next/core-web-vitals'
],
'parser': '@typescript-eslint/parser',
'parserOptions': {
'ecmaFeatures': {'jsx': true},
'ecmaVersion': 2022,
'sourceType': 'module',
'tsconfigRootDir': __dirname,
'project': ['./tsconfig.json']
},
'plugins': [
'@typescript-eslint',
'react',
'tailwindcss',
'unused-imports',
'simple-import-sort',
'import'
],
'settings': {
'react': {'version': 'detect'},
'import/resolver': {'typescript': {}}
},
'rules': {
'import/default': 0,
'no-mixed-spaces-and-tabs': 2,
'react/prop-types': 0,
'no-async-promise-executor': 0,
'import/no-unresolved': 0, //Issue with package exports
'quotes': [2, 'single', {'avoidEscape': true}],
'object-curly-spacing': [2, 'never'],
'array-bracket-spacing': [2, 'never'],
'semi': 'error',
'no-else-return': ['error', {'allowElseIf': false}],
'eol-last': ['error', 'always'],
'import/no-named-as-default-member': 2,
'tailwindcss/no-custom-classname': 0,
'array-bracket-newline': ['error', {'multiline': true}],
'react/jsx-curly-brace-presence': ['error', {'props': 'always', 'children': 'always'}],
'react/jsx-first-prop-new-line': ['error', 'multiline'],
'react/jsx-max-props-per-line': ['error', {'maximum': {'single': 2, 'multi': 1}}],
'react/jsx-closing-tag-location': 2,
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn', {
'vars': 'all',
'varsIgnorePattern': '^_',
'args': 'after-used',
'argsIgnorePattern': '^_'
}
],
'simple-import-sort/imports': 2,
'simple-import-sort/exports': 2,
'import/first': 2,
'import/newline-after-import': 2,
'import/no-duplicates': 2,
'curly': ['error', 'all'],
'object-curly-newline': [
'error', {
'ObjectExpression': {'multiline': true, 'consistent': true},
'ObjectPattern': {'multiline': true, 'consistent': true},
'ImportDeclaration': 'never',
'ExportDeclaration': {'multiline': true, 'minProperties': 3}
}
],
'object-property-newline': ['error', {'allowAllPropertiesOnSameLine': true}],
'prefer-destructuring': ['error', {'array': true, 'object': true}, {'enforceForRenamedProperties': false}],
'@typescript-eslint/consistent-type-imports': [
2, {
'prefer': 'type-imports',
'disallowTypeAnnotations': true,
'fixStyle': 'separate-type-imports'
}
],
'no-multi-spaces': ['error', {ignoreEOLComments: false}],
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/no-unused-vars': 2,
'@typescript-eslint/array-type': ['error', {'default': 'array'}],
'@typescript-eslint/consistent-type-assertions': ['error', {'assertionStyle': 'as', 'objectLiteralTypeAssertions': 'never'}],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/consistent-indexed-object-style': ['error', 'index-signature'],
'@typescript-eslint/explicit-function-return-type': [
'error', {
'allowExpressions': false,
'allowTypedFunctionExpressions': false,
'allowHigherOrderFunctions': false,
'allowDirectConstAssertionInArrowFunctions': false,
'allowConciseArrowFunctionExpressionsStartingWithVoid': false,
'allowedNames': []
}
],
'@typescript-eslint/naming-convention': [
'error',
{'selector': 'default', 'format': ['camelCase']},
{'selector': 'function', 'format': ['camelCase', 'PascalCase']},

{'selector': 'variableLike', 'format': ['camelCase', 'PascalCase', 'UPPER_CASE'], 'leadingUnderscore': 'allow'},
{'selector': 'variable', 'types': ['boolean'], 'format': ['PascalCase'], 'prefix': ['is', 'are', 'should', 'has', 'can', 'did', 'will', 'with']},
{
'selector': 'default',
'format': null,
'filter': {'regex': '^(0-9)$', 'match': false}
},
{
'selector': 'variableLike',
'filter': {'regex': '^(set)', 'match': true},
'format': ['camelCase'],
'prefix': ['set_']
},
{
'selector': 'variableLike',
'format': ['PascalCase'],
'filter': {'regex': '(Context)$|(ContextApp)$|^Component$', 'match': true}
},
{'selector': ['typeParameter', 'typeAlias'], 'format': ['PascalCase'], 'prefix': ['T']},
{'selector': 'interface', 'format': ['PascalCase'], 'prefix': ['I']},
{
'selector': ['default', 'variableLike', 'parameter'],
'format': null,
'filter': {'regex': '^(__html|_css)$', 'match': true}
}
],
'@typescript-eslint/no-misused-promises': ['error', {'checksConditionals': true, 'checksVoidReturn': false}],
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error',
'@typescript-eslint/no-unnecessary-qualifier': 'error',
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': [
'error', {
'allowComparingNullableBooleansToTrue': false,
'allowComparingNullableBooleansToFalse': false
}
],
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/require-array-sort-compare': 'error',
'@typescript-eslint/type-annotation-spacing': [
'error', {
'before': true,
'after': true,
'overrides': {'colon': {'before': false, 'after': true}}
}
],
'brace-style': 'off',
'@typescript-eslint/brace-style': ['error', '1tbs'],
'comma-dangle': 'off',
'@typescript-eslint/comma-dangle': ['error'],
'comma-spacing': 'off',
'@typescript-eslint/comma-spacing': ['error'],
'dot-notation': 'off',
'@typescript-eslint/dot-notation': ['error'],
'indent': 'off',
'@typescript-eslint/indent': ['error', 'tab']
},
overrides: [
{
files: ['*.{ts,tsx}'],
rules: {
'simple-import-sort/imports': [
'error',
{
groups: [
[
'^react',
'^next',
'^(ethers|ethcall)?\\w',
'^axios', '^swr',
'^tailwindcss', '^framer-motion', '^nprogress',
'^@?\\w',
'^(@yearn-finance/.*)?\\w',
'^(@common/.*)?\\w',
'^(@y.*)?\\w'
],
// Parent imports.
['^\\u0000', '^\\.\\.(?!/?$)', '^\\.\\./?$', '^\\./?$', '^\\.(?!/?$)', '^\\./(?=.*/)(?!/?$)'],
//Types imports.
[
'^node:.*\\u0000$',
'^(@yearn-finance)?\\w.*\\u0000$',
'^(@common)?\\w.*\\u0000$',
'^(@y.*)?\\w.*\\u0000$',
'^@?\\w.*\\u0000$',
'^[^.].*\\u0000$',
'^\\..*\\u0000$'
],

// Style imports.
['^.+\\.s?css$']
]
}
]
}
}
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import fs from 'fs';

type TContext = {
params: {
chainID: string
tokenAddress: string
filename: string
}
}
export async function GET(request: Request, context: TContext) {
const chainIDStr = (context?.params?.chainID || 1).toString()
const tokenAddress = (context?.params?.tokenAddress || '').toLowerCase()
const fileName = (context?.params?.filename || '').toLowerCase()
if (!['logo.svg', 'logo-32.png', 'logo-128.png'].includes(fileName)) {
return new Response('Not found', {status: 404})
}
const logo = fs.readFileSync(`../../${chainIDStr}/${tokenAddress}/${fileName}`)

if (fileName.endsWith('.svg')) {
return new Response(logo, {headers: {'Content-Type': 'image/svg+xml'}})
}
return new Response(logo, {headers: {'Content-Type': 'image/png'}})
}
Binary file added _config/nodeAPI/app/favicon.ico
Binary file not shown.
8 changes: 8 additions & 0 deletions _config/nodeAPI/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
},
}

module.exports = nextConfig
43 changes: 43 additions & 0 deletions _config/nodeAPI/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "tokenassets",
"version": "0.0.1",
"files": [
"."
],
"scripts": {
"dev": "next dev",
"dev:ts": "tsc --watch",
"start": "tsc && next build && next start",
"build": "tsc && next build",
"export": "tsc && next build && next export -o ipfs",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
"react": "18.2.0",
"react-dom": "^18.2.0",
"next": "^13.2.4"
},
"devDependencies": {
"@types/express": "^4.17.17",
"@types/ioredis": "^4.28.10",
"@types/jest": "29.4.3",
"@types/node": "^18.14.0",
"@types/nprogress": "^0.2.0",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"eslint": "^8.34.0",
"eslint-config-next": "^13.1.6",
"eslint-import-resolver-typescript": "^3.5.3",
"eslint-plugin-brackets": "^0.1.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-tailwindcss": "^3.9.0",
"eslint-plugin-unused-imports": "^2.0.0",
"ts-loader": "^9.4.2",
"typescript": "^4.9.5"
}
}
28 changes: 28 additions & 0 deletions _config/nodeAPI/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 79b7132

Please sign in to comment.