diff --git a/index.ts b/index.ts index 2aa0e7a..3a976ee 100644 --- a/index.ts +++ b/index.ts @@ -12,20 +12,22 @@ const sendError = (req, res, error) => { } const badgeHandlers = fs.readdirSync(path.join(__dirname, 'endpoints')) - .filter(name => !name.startsWith('_')) - .map(name => name.replace(/\.ts$/, '')) + .filter(name => /\.[jt]s$/.test(name)) + .map(name => name.replace(/\.[jt]s$/, '')) const isStatic = (url) => { if (url === '/') return true - if (url.startsWith('/static/')) return true if (url.startsWith('/_next/')) return true + if (url.startsWith('/static/')) return true + if (url.startsWith('/builder')) return true return false } +const { PUB_DIR = '.' } = process.env const server = http.createServer(async (req, res) => { // handle statics if (isStatic(req.url)) { - return serveHandler(req, res, { public: path.join(__dirname, 'dist') }) + return serveHandler(req, res, { public: path.resolve(__dirname, PUB_DIR) }) } // handle `/docs/:name` diff --git a/next.config.js b/next.config.js index 0fbd0e5..f82dcf1 100644 --- a/next.config.js +++ b/next.config.js @@ -1,3 +1,9 @@ module.exports = { - target: 'serverless' + target: 'serverless', + exportPathMap: async function (defaultPathMap) { + return { + '/': { page: '/index' }, + '/builder': { page: '/builder' } + } + } } diff --git a/package.json b/package.json index ec2f0ab..eb42baf 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,12 @@ "private": true, "scripts": { "lint": "standard", - "predev": "npm run now-build", - "dev": "nodemon -e ts,js -w endpoints -w libs -x 'ts-node index.ts'", + "build": "npm run tools && next build && next export -o dist && tsc", + "predev": "npm run build", + "dev": "PUB_DIR=dist nodemon -e ts,js -w endpoints -w libs -x 'ts-node index.ts'", "dev:web": "next", "tools": "ts-node tools/gen-examples.ts", - "now-build": "npm run tools && next build && next export -o dist", + "now-build": "npm run build", "pretest": "npm run lint", "test": "tap test/*.js --reporter spec -j12", "start": "node service.js", diff --git a/tsconfig.json b/tsconfig.json index e0e0c7a..de3f1a0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,7 @@ "moduleResolution": "node", "esModuleInterop": true, "sourceMap": true, - "outDir": "dist-server", + "outDir": "dist", "baseUrl": ".", "lib": ["dom", "esnext"] },