Update dev & deploy scripts

pull/282/head
Amio 2019-05-26 18:30:45 +08:00
rodzic 8bdc6be0f0
commit 4808e03f3a
5 zmienionych plików z 28 dodań i 7 usunięć

1
.gitignore vendored
Wyświetl plik

@ -2,5 +2,6 @@ node_modules
yarn.lock
public
dist
out
.gen
.next

Wyświetl plik

@ -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 {

Wyświetl plik

@ -1,3 +1,8 @@
module.exports = {
target: 'serverless'
target: 'serverless',
exportPathMap: async function (defaultPathMap) {
return {
'/': { page: '/' }
}
}
}

Wyświetl plik

@ -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" }

Wyświetl plik

@ -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"