Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server/index.js requirement / typescript support #847

Open
dcsan opened this issue Jul 19, 2020 · 2 comments
Open

server/index.js requirement / typescript support #847

dcsan opened this issue Jul 19, 2020 · 2 comments

Comments

@dcsan
Copy link

dcsan commented Jul 19, 2020

Describe the bug
It seems bottender has a hardwired path expecting an index.js in the same directory as you run the server.
I'm moving a project to typescript so the raw source is under src and I usually run in dev with ts-node

➜  server git:(move-to-ts) ✗ ts-node src/server.js
Error: Cannot find module '/Users/dc/dev/exiteer/xbot/server/index.js'
Require stack:
- /Users/dc/dev/exiteer/xbot/server/node_modules/bottender/dist/server/Server.js
- /Users/dc/dev/exiteer/xbot/server/node_modules/bottender/dist/bottender.js
- /Users/dc/dev/exiteer/xbot/server/node_modules/bottender/dist/index.js
- /Users/dc/dev/exiteer/xbot/server/src/server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15)
    at Function.Module._load (internal/modules/cjs/loader.js:898:27)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
    at require (internal/modules/cjs/helpers.js:73:18)
    at DevServer.<anonymous> (/Users/dc/dev/exiteer/xbot/server/node_modules/bottender/src/server/Server.ts:51:37)
    at Generator.next (<anonymous>)
    at /Users/dc/dev/exiteer/xbot/server/node_modules/bottender/dist/server/Server.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/dc/dev/exiteer/xbot/server/node_modules/bottender/dist/server/Server.js:4:12)
    at DevServer.prepare (/Users/dc/dev/exiteer/xbot/server/node_modules/bottender/dist/server/Server.js:47:16)


I'm wondering if there's a way to pass the routes file to botTender explicitly when starting up?

src/server.js

const bot = bottender({
  dev: process.env.NODE_ENV !== 'production',
});
// the request handler of the bottender app
const handle = bot.getRequestHandler();

bot.prepare().then(() => {
  const server = express();

botRouter.js

const { router, text, slack } = require('bottender/router')
const Dispatcher = require('./mup/Dispatcher')

const botRoutes = async function App () {
  // Logger.log('init routes game', game)

  const routes = router([
    text(/^e$|^echo$/i, Dispatcher.echo),

I'm not quite sure how to wire those things together, there seems to be some lazy loading going on with the routing currently.

Expected behavior
A more explicit way to startup a project, less magic requires happening behind the scenes...

This is mainly to support a project in typescript

@aqzhyi
Copy link
Contributor

aqzhyi commented Jul 22, 2020

Hello, I am not sure what your essential question point is. Unfortunately, I have never used ts-node

here is my currently solution:

// project/index.js
module.exports = require('./dist/node/index.js').default

and

// project/src/server.ts
...
server.use(express.static('dist')) // to serve frontend
...
// project/src/...others.ts // and so on

currently, I use webpack { target: 'node' } and npm:webpack-node-externals to build out dist codes.

maybe, soon, https://deno.land/ could be better

@marines
Copy link

marines commented Jan 14, 2021

The point is to not hardcode file names and let users provide routing programmatically. It has little to do with ts-node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants