add next api routes, remove netlify deps
This commit is contained in:
@@ -82,10 +82,7 @@ class MultiSigForm extends React.Component {
|
||||
};
|
||||
}),
|
||||
};
|
||||
const res = await axios.post(
|
||||
"/.netlify/functions/create-multisig",
|
||||
multisig
|
||||
);
|
||||
const res = await axios.post("/api/multisig", multisig);
|
||||
const multiAddress = res.data.data.address;
|
||||
this.props.router.push(`/multi/${multiAddress}`);
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,5 +0,0 @@
|
||||
# example netlify.toml
|
||||
[build]
|
||||
command = "npm run build && npm run export"
|
||||
functions = "lambda-build"
|
||||
publish = "out"
|
||||
+3
-22
@@ -1,14 +1,9 @@
|
||||
{
|
||||
"name": "create-next-example-app",
|
||||
"scripts": {
|
||||
"dev": "next",
|
||||
"build": "npm-run-all --parallel build:**",
|
||||
"build:app": "next build",
|
||||
"build:functions": "netlify-lambda build lambda",
|
||||
"start": "npm-run-all --parallel start:app start:server",
|
||||
"start:app": "PORT=3000 node server.js",
|
||||
"start:server": "netlify-lambda serve lambda",
|
||||
"export": "next export"
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start"
|
||||
},
|
||||
"dependencies": {
|
||||
"@cosmjs/launchpad": "^0.23.2",
|
||||
@@ -22,19 +17,5 @@
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"uuid": "^8.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"express": "^4.17.1",
|
||||
"http-proxy-middleware": "^1.0.6",
|
||||
"netlify-lambda": "^2.0.3",
|
||||
"npm-run-all": "^4.1.5"
|
||||
},
|
||||
"proxy": {
|
||||
"/.netlify/functions": {
|
||||
"target": "http://localhost:9000",
|
||||
"pathRewrite": {
|
||||
"^/\\.netlify/functions": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import faunadb from "faunadb";
|
||||
|
||||
export default async function (req, res) {
|
||||
return new Promise(async (resolve) => {
|
||||
switch (req.method) {
|
||||
case "POST":
|
||||
const q = faunadb.query;
|
||||
const client = new faunadb.Client({
|
||||
secret: process.env.FAUNADB_SECRET,
|
||||
});
|
||||
console.log(req.body);
|
||||
try {
|
||||
const data = req.body;
|
||||
console.log("Function `createMultisig` invoked", data);
|
||||
const multisig = {
|
||||
data: data,
|
||||
};
|
||||
const faunaRes = await client.query(
|
||||
q.Create(q.Collection("Multisig"), multisig)
|
||||
);
|
||||
console.log("success", faunaRes);
|
||||
res.status(200).send(faunaRes);
|
||||
return resolve();
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
res.status(400).send(err.message);
|
||||
return resolve();
|
||||
}
|
||||
}
|
||||
// no route matched
|
||||
res.status(405).end();
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
// server.js
|
||||
/* eslint-disable no-console */
|
||||
const express = require("express");
|
||||
const next = require("next");
|
||||
|
||||
const devProxy = {
|
||||
"/.netlify": {
|
||||
target: "http://localhost:9000",
|
||||
pathRewrite: { "^/.netlify/functions": "" },
|
||||
},
|
||||
};
|
||||
|
||||
const port = parseInt(process.env.PORT, 10) || 3000;
|
||||
const env = process.env.NODE_ENV;
|
||||
const dev = env !== "production";
|
||||
const app = next({
|
||||
dir: ".", // base directory where everything is, could move to src later
|
||||
dev,
|
||||
});
|
||||
|
||||
const handle = app.getRequestHandler();
|
||||
|
||||
let server;
|
||||
app
|
||||
.prepare()
|
||||
.then(() => {
|
||||
server = express();
|
||||
|
||||
// Set up the proxy.
|
||||
if (dev && devProxy) {
|
||||
const { createProxyMiddleware } = require("http-proxy-middleware");
|
||||
Object.keys(devProxy).forEach(function (context) {
|
||||
server.use(createProxyMiddleware(context, devProxy[context]));
|
||||
});
|
||||
}
|
||||
|
||||
// Default catch-all handler to allow Next.js to handle all other routes
|
||||
server.all("*", (req, res) => handle(req, res));
|
||||
|
||||
server.listen(port, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
console.log(`> Ready on port ${port}`);
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("An error occurred, unable to start the server");
|
||||
console.log(err);
|
||||
});
|
||||
Reference in New Issue
Block a user