I’m creating an typescript express api and I want to export it
What’s the es6 equivalent for
app.use(bodyParser);
app.post('/updatestate', (req, res) => {
const newValue = updateDatabase(res.body);
res.json(newValue);
});
module.exports.handler = serverless(app);
in the .ts lambda file?
And if the function is deployed in http://localhost:9999/.netlify/functions/abc ,
the request should me made in http://localhost:9999/.netlify/functions/abc/updatestate
to update the database?
Hey @rafael.polonio ,
Your question is more of a coding question than a Netlify question. We cannot provide extended support for such, but here’s an example of a repo using Netlify Functions + TypeScript + Express:
// noinspection AnonymousFunctionJS, ChainedFunctionCallJS, ConstantOnRightSideOfComparisonJS, FunctionWithInconsistentReturnsJS, FunctionWithMultipleReturnPointsJS, JSUnusedGlobalSymbols, MagicNumberJS, NestedFunctionCallJS, NestedFunctionJS, ParameterNamingConventionJS
import type {HandlerContext, HandlerEvent} from '@netlify/functions'
import type {NextFunction, Request, Response} from 'express'
import axios from 'axios'
import cookieParser from 'cookie-parser'
import cryptoJs from 'crypto-js'
import express, {json, Router} from 'express'
import serverless from 'serverless-http'
import {ApiError} from '~/server/data/constants'
import forumsPosts from '~/server/routes/forumsPosts'
import oauthAuthorize from '~/server/routes/oauthAuthorize'
import oauthCallback from '~/server/routes/oauthCallback'
import systemStatus from '~/server/routes/systemStatus'
import ticketList from '~/server/routes/ticketList'
import ticketNew from '~/server/routes/ticketNew'
import ticketUpdate from '~/server/routes/ticketUpdate'
import ticketView from '~/server/routes/ticketView'
import userLogout from '~/server/routes/userLogout'
import userSites from '~/server/routes/userSites'
This file has been truncated. show original