create-bridge-app
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -10,2 +10,3 @@ #!/usr/bin/env node | ||
const prettier_1 = __importDefault(require("prettier")); | ||
const code_1 = require("./code"); | ||
// import minimist from 'minimist'; | ||
@@ -38,50 +39,3 @@ // const argv = minimist(process.argv.slice(2)); | ||
}); | ||
fs_1.default.writeFile(`${name}/index.ts`, prettier_1.default.format(`import { initBridge, handler, onError, StatusCode, httpError, apply } from 'bridge'; | ||
import express from 'express'; | ||
import z from 'zod'; | ||
const port = 8080; | ||
const authMiddleware = handler({ | ||
headers: z.object({ token: z.string().min(5) }), | ||
resolve: ({ headers }) => { | ||
if (headers.token !== 'private_token') return httpError(StatusCode.UNAUTHORIZED, 'Wrong token'); | ||
else return { firstName: 'John', name: 'Doe', age: 21 }; | ||
}, | ||
}); | ||
const updateUser = handler({ | ||
middlewares: apply(authMiddleware), | ||
body: z.object({ age: z.number() }), | ||
resolve: ({ mid, body }) => { | ||
const user = mid; | ||
user.age = body.age; | ||
return user; | ||
}, | ||
}); | ||
const routes = { | ||
hey: handler({ resolve: () => 'hey' }), | ||
hello: handler({ | ||
query: z.object({ name: z.string().optional() }), | ||
method: 'GET', | ||
resolve: ({ query }) => \`Hello \${query.name}\`, | ||
}), | ||
user: { | ||
update: updateUser, | ||
}, | ||
}; | ||
const errorHandler = onError(({ error, path }) => { | ||
if (error.name === 'Internal server error') console.log(path, error); // Send to bug reporting | ||
else console.log(path, error.status, error.name); | ||
}); | ||
const app = express(); | ||
app.use('', initBridge({ routes, errorHandler }).expressMiddleware()); | ||
app.listen(port, () => { | ||
console.log(\`Listening on port \${port}\`); | ||
});`, { parser: 'typescript' }), () => { }); | ||
fs_1.default.writeFile(`${name}/index.ts`, prettier_1.default.format(code_1.indexFile, { parser: 'typescript' }), () => { }); | ||
}, | ||
@@ -88,0 +42,0 @@ }); |
{ | ||
"name": "create-bridge-app", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Create Bridge-powered Express app with one command", | ||
@@ -5,0 +5,0 @@ "author": "Bridge Team <support@bridge.codes>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6560
5
123