kopia lustrzana https://github.com/badgen/badgen.net
Update dev & deploy scripts
rodzic
8bdc6be0f0
commit
4808e03f3a
|
@ -2,5 +2,6 @@ node_modules
|
|||
yarn.lock
|
||||
public
|
||||
dist
|
||||
out
|
||||
.gen
|
||||
.next
|
||||
|
|
14
index.ts
14
index.ts
|
@ -1,6 +1,7 @@
|
|||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import http from 'http'
|
||||
import serveHandler from 'serve-handler'
|
||||
|
||||
import serve404 from './libs/serve-404'
|
||||
|
||||
|
@ -13,7 +14,20 @@ const badgeHandlers = fs.readdirSync(path.join(__dirname, 'endpoints'))
|
|||
.filter(name => !name.startsWith('_'))
|
||||
.map(name => name.replace(/\.ts$/, ''))
|
||||
|
||||
const isStatic = (url) => {
|
||||
if (url === '/') return true
|
||||
if (url.startsWith('/static/')) return true
|
||||
if (url.startsWith('/_next/')) return true
|
||||
return false
|
||||
}
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
// handle statics
|
||||
if (isStatic(req.url)) {
|
||||
return serveHandler(req, res, { public: path.join(__dirname, 'out') })
|
||||
}
|
||||
|
||||
// handle endpoints
|
||||
const handlerName = badgeHandlers.find(h => req.url!.startsWith(`/${h}`))
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
module.exports = {
|
||||
target: 'serverless'
|
||||
target: 'serverless',
|
||||
exportPathMap: async function (defaultPathMap) {
|
||||
return {
|
||||
'/': { page: '/' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
4
now.json
4
now.json
|
@ -5,7 +5,9 @@
|
|||
],
|
||||
"builds": [
|
||||
{ "src": "endpoints/*.ts", "use": "@now/node" },
|
||||
{ "src": "next.config.js", "use": "@now/next" }
|
||||
{ "src": "package.json", "use": "@now/static-build", "config": {
|
||||
"distDir": "out"
|
||||
} }
|
||||
],
|
||||
"routes": [
|
||||
{ "src": "/(?<name>\\w+)/.*", "dest": "/endpoints/$name.ts" }
|
||||
|
|
|
@ -5,18 +5,17 @@
|
|||
"license": "ISC",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev2": "nodemon -e ts,js -w endpoints -x 'ts-node index.ts'",
|
||||
"lint": "standard",
|
||||
"dev": "micro-dev service.js -s -i .next",
|
||||
"dev": "nodemon -e ts,js -w endpoints -w libs -x 'ts-node index.ts'",
|
||||
"dev:web": "next",
|
||||
"build": "tsc",
|
||||
"tools": "ts-node tools/gen-examples.ts",
|
||||
"now-build": "npm run tools && next build && next export",
|
||||
"pretest": "npm run lint",
|
||||
"test": "tap test/*.js --reporter spec -j12",
|
||||
"start": "node service.js",
|
||||
"now-prune": "now rm badgen.net --safe -y -S amio || true",
|
||||
"predeploy": "now -S amio inspect badgen.net",
|
||||
"deploy": "now -S amio && now -S amio alias",
|
||||
"canary": "now -S amio && now -S amio alias badgen-canary"
|
||||
"deploy": "now -S amio && now -S amio alias"
|
||||
},
|
||||
"standard": {
|
||||
"parser": "babel-eslint"
|
||||
|
|
Ładowanie…
Reference in New Issue