Files
archived-starters/javascript/with-next-js/pages/api/data.js
Jake Runzer 07b4eb1e20 Update JavaScript examples to latest Railway (#14)
* update serverless pg example
* update nextjs example
* update prisma example
2020-10-07 20:17:31 +01:00

23 lines
507 B
JavaScript

// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
// Call Railway anywhere on serverside code.
// Here or getInitialProps
import { promisify } from "util";
import pg from "pg";
export default async (req, res) => {
try {
const client = pg.Pool();
const query = await promisify(client.query)("Select NOW()");
res.json({
data: {
time: query.rows[0].now,
},
});
} catch (e) {
console.log("ERROR", e);
res.json({ error: e });
}
};